more pytermtk stuff added
This commit is contained in:
1 parent
c0986f8d2d
commit
cb01fa2aee
3 files changed
+144
-100
No files matched your search
+77
-67
@@ -16,72 +16,6 @@ import requests
|
|||||||
# u = 'pseudo'
|
# u = 'pseudo'
|
||||||
# p = 'telegram9dock-MICHEL'
|
# p = 'telegram9dock-MICHEL'
|
||||||
|
|
||||||
class Artist:
|
|
||||||
id: str
|
|
||||||
name: str
|
|
||||||
albumCount: int
|
|
||||||
coverArt: str
|
|
||||||
artistImageUrl: str
|
|
||||||
|
|
||||||
def __init__(self, id: str, name: str, albumCount: str | int, coverArt: str, artistImageUrl: str):
|
|
||||||
self.id = id
|
|
||||||
self.name = name
|
|
||||||
self.albumCount = int(albumCount)
|
|
||||||
self.coverArt = coverArt
|
|
||||||
self.artistImageUrl = artistImageUrl
|
|
||||||
|
|
||||||
class ArtistIndex:
|
|
||||||
name: str
|
|
||||||
artists: list[Artist]
|
|
||||||
|
|
||||||
def __init__(self, indexInfo: dict, artists: list[dict]):
|
|
||||||
self.name = indexInfo['name']
|
|
||||||
|
|
||||||
self.artists = []
|
|
||||||
for artist in artists:
|
|
||||||
self.artists.append(Artist(
|
|
||||||
artist['id'],
|
|
||||||
artist['name'],
|
|
||||||
artist['albumCount'],
|
|
||||||
artist['coverArt'],
|
|
||||||
artist['artistImageUrl']
|
|
||||||
))
|
|
||||||
|
|
||||||
class ArtistIndexes:
|
|
||||||
indexes: list[ArtistIndex]
|
|
||||||
|
|
||||||
def __init__(self, xml_data: bytes):
|
|
||||||
self._parseXml(xml_data.decode('utf-8'))
|
|
||||||
|
|
||||||
def _parseXml(self, xml_data: str):
|
|
||||||
root = xml.etree.ElementTree.fromstring(xml_data)
|
|
||||||
|
|
||||||
self.indexes: list[ArtistIndex] = []
|
|
||||||
|
|
||||||
if root.get('status') != 'ok':
|
|
||||||
return None
|
|
||||||
|
|
||||||
in_index = False
|
|
||||||
artists = []
|
|
||||||
index_info = None
|
|
||||||
for item in root.iter():
|
|
||||||
# print(item.tag, dict(item.items()))
|
|
||||||
|
|
||||||
if item.tag == '{http://subsonic.org/restapi}index':
|
|
||||||
|
|
||||||
if in_index:
|
|
||||||
in_index = not in_index
|
|
||||||
|
|
||||||
self.indexes.append(ArtistIndex(index_info, artists))
|
|
||||||
|
|
||||||
artists = []
|
|
||||||
else:
|
|
||||||
in_index = not in_index
|
|
||||||
index_info = dict(item.items())
|
|
||||||
|
|
||||||
elif item.tag == '{http://subsonic.org/restapi}artist':
|
|
||||||
artists.append(dict(item.items()))
|
|
||||||
|
|
||||||
class Album:
|
class Album:
|
||||||
id: str
|
id: str
|
||||||
title: str
|
title: str
|
||||||
@@ -138,6 +72,73 @@ class Song:
|
|||||||
self.channelCount = int(song_info['channelCount'])
|
self.channelCount = int(song_info['channelCount'])
|
||||||
self.samplingRate = int(song_info['samplingRate'])
|
self.samplingRate = int(song_info['samplingRate'])
|
||||||
|
|
||||||
|
class Artist:
|
||||||
|
id: str
|
||||||
|
name: str
|
||||||
|
albumCount: int
|
||||||
|
coverArt: str
|
||||||
|
artistImageUrl: str
|
||||||
|
|
||||||
|
def __init__(self, id: str, name: str, albumCount: str | int, coverArt: str, artistImageUrl: str):
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
self.albumCount = int(albumCount)
|
||||||
|
self.coverArt = coverArt
|
||||||
|
self.artistImageUrl = artistImageUrl
|
||||||
|
|
||||||
|
|
||||||
|
class ArtistIndex:
|
||||||
|
name: str
|
||||||
|
artists: list[Artist]
|
||||||
|
|
||||||
|
def __init__(self, indexInfo: dict, artists: list[dict]):
|
||||||
|
self.name = indexInfo['name']
|
||||||
|
|
||||||
|
self.artists = []
|
||||||
|
for artist in artists:
|
||||||
|
self.artists.append(Artist(
|
||||||
|
artist['id'],
|
||||||
|
artist['name'],
|
||||||
|
artist['albumCount'],
|
||||||
|
artist['coverArt'],
|
||||||
|
artist['artistImageUrl']
|
||||||
|
))
|
||||||
|
|
||||||
|
class ArtistIndexes:
|
||||||
|
indexes: list[ArtistIndex]
|
||||||
|
|
||||||
|
def __init__(self, xml_data: bytes):
|
||||||
|
self._parseXml(xml_data.decode('utf-8'))
|
||||||
|
|
||||||
|
def _parseXml(self, xml_data: str):
|
||||||
|
root = xml.etree.ElementTree.fromstring(xml_data)
|
||||||
|
|
||||||
|
self.indexes: list[ArtistIndex] = []
|
||||||
|
|
||||||
|
if root.get('status') != 'ok':
|
||||||
|
return None
|
||||||
|
|
||||||
|
in_index = False
|
||||||
|
artists = []
|
||||||
|
index_info = None
|
||||||
|
for item in root.iter():
|
||||||
|
# print(item.tag, dict(item.items()))
|
||||||
|
|
||||||
|
if item.tag == '{http://subsonic.org/restapi}index':
|
||||||
|
|
||||||
|
if in_index:
|
||||||
|
in_index = not in_index
|
||||||
|
|
||||||
|
self.indexes.append(ArtistIndex(index_info, artists))
|
||||||
|
|
||||||
|
artists = []
|
||||||
|
else:
|
||||||
|
in_index = not in_index
|
||||||
|
index_info = dict(item.items())
|
||||||
|
|
||||||
|
elif item.tag == '{http://subsonic.org/restapi}artist':
|
||||||
|
artists.append(dict(item.items()))
|
||||||
|
|
||||||
class SubpyConn:
|
class SubpyConn:
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
@@ -205,14 +206,23 @@ class SubpyConn:
|
|||||||
r: requests.Response = self._getMusicDirectory(album_id)
|
r: requests.Response = self._getMusicDirectory(album_id)
|
||||||
xml_data: str = r.content.decode('utf-8')
|
xml_data: str = r.content.decode('utf-8')
|
||||||
|
|
||||||
root: xml.etree.ElementTree.ElementTree = xml.etree.ElementTree.fromstring(xml_data)
|
if r.status_code != 200:
|
||||||
|
return []
|
||||||
|
|
||||||
|
root: xml.etree.ElementTree.Element = xml.etree.ElementTree.fromstring(xml_data)
|
||||||
songs: list[Song] = []
|
songs: list[Song] = []
|
||||||
|
|
||||||
|
if root.get('status') != 'ok':
|
||||||
|
return []
|
||||||
|
|
||||||
for item in root.iter():
|
for item in root.iter():
|
||||||
|
|
||||||
if item.tag == '{http://subsonic.org/restapi}child':
|
if item.tag == '{http://subsonic.org/restapi}child':
|
||||||
songs.append(Song(dict(item.items())))
|
songs.append(Song(dict(item.items())))
|
||||||
|
|
||||||
|
for song in songs:
|
||||||
|
print(song.title)
|
||||||
|
|
||||||
return songs
|
return songs
|
||||||
|
|
||||||
def getArtists(self) -> list[Artist]:
|
def getArtists(self) -> list[Artist]:
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ requests==2.31.0
|
|||||||
simpleaudio==1.0.4
|
simpleaudio==1.0.4
|
||||||
urwid==2.6.16
|
urwid==2.6.16
|
||||||
py-sonic==1.0.1
|
py-sonic==1.0.1
|
||||||
|
pyTermTk==0.41.0a54
|
||||||
+66
-33
@@ -4,50 +4,83 @@ import SubSonic
|
|||||||
|
|
||||||
u = 'pseudo'
|
u = 'pseudo'
|
||||||
p = 'telegram9dock-MICHEL'
|
p = 'telegram9dock-MICHEL'
|
||||||
conn = SubSonic.SubpyConn(u, p, "https://music.0x01fe.net")
|
|
||||||
|
|
||||||
echidna_id = "937004317800a879f0cddd471fb82387"
|
echidna_id = "937004317800a879f0cddd471fb82387"
|
||||||
|
|
||||||
|
class SubPlayer:
|
||||||
|
conn: SubSonic.SubpyConn
|
||||||
|
|
||||||
artists = conn.getArtists()
|
artists: list[SubSonic.Artist]
|
||||||
selected_artist = None
|
|
||||||
|
|
||||||
root = ttk.TTk(layout=ttk.TTkHBoxLayout())
|
selected_artist: SubSonic.Artist
|
||||||
|
selected_album: SubSonic.Album
|
||||||
|
|
||||||
# window = ttk.TTkWindow(parent=root, pos=(1, 1), size=(100, 30), title="Testing", border=True)
|
def __init__(self, conn: SubSonic.SubpyConn):
|
||||||
|
self.conn = conn
|
||||||
|
|
||||||
# ttk.TTkLabel(parent=window, pos=(5,2), text='hello world')
|
def run(self) -> None:
|
||||||
# artistMenu = ttk.TTkMenu(title="Artists", parent=root, border=True, size=(100, 30))
|
self.artists = conn.getArtists()
|
||||||
# for artist in artists:
|
self.root = ttk.TTk(layout=ttk.TTkHBoxLayout())
|
||||||
# newButton = ttk.TTkMenuButton(text=artist.name, parent=artistMenu)
|
|
||||||
# artistMenu.addMenuItem(newButton)
|
|
||||||
|
|
||||||
artistList = ttk.TTkList(
|
self.artistList = ttk.TTkList(
|
||||||
name="Artists",
|
name="Artists",
|
||||||
parent=root,
|
parent=self.root,
|
||||||
items=[artist.name for artist in artists]
|
items=[artist.name for artist in self.artists]
|
||||||
)
|
)
|
||||||
|
|
||||||
albumList = ttk.TTkList(
|
self.albumList = ttk.TTkList(
|
||||||
name="ArtistAlbums",
|
name="ArtistAlbums",
|
||||||
parent=root
|
parent=self.root
|
||||||
)
|
)
|
||||||
|
|
||||||
@ttk.pyTTkSlot(ttk.TTkWidgets.listwidget.TTkAbstractListItem)
|
self.songList = ttk.TTkList(
|
||||||
def clickArtist(v: ttk.TTkWidgets.listwidget.TTkAbstractListItem):
|
name="AlbumSongs",
|
||||||
# ttk.TTkLog.debug('test')
|
parent=self.root
|
||||||
# print(v.text())
|
)
|
||||||
|
|
||||||
artist_name = v.text()
|
|
||||||
for artist in artists:
|
|
||||||
if artist.name == artist_name:
|
|
||||||
selected_artist = artist.id
|
|
||||||
|
|
||||||
albumList.removeItems(albumList.items())
|
|
||||||
albumList.addItems([album.name for album in conn.getArtistAlbums(selected_artist)])
|
|
||||||
|
|
||||||
|
|
||||||
artistList.itemClicked.connect(clickArtist)
|
self.artistList.itemClicked.connect(self.clickArtist)
|
||||||
|
self.albumList.itemClicked.connect(self.clickAlbum)
|
||||||
|
|
||||||
root.mainloop()
|
self.root.mainloop()
|
||||||
|
|
||||||
|
def _clearSongs(self) -> None:
|
||||||
|
self.songList.removeItems(self.songList.items())
|
||||||
|
|
||||||
|
def _clearAlbums(self) -> None:
|
||||||
|
self.albumList.removeItems(self.albumList.items())
|
||||||
|
|
||||||
|
@ttk.pyTTkSlot(ttk.TTkWidgets.listwidget.TTkAbstractListItem)
|
||||||
|
def clickArtist(self, v: ttk.TTkWidgets.listwidget.TTkAbstractListItem):
|
||||||
|
# ttk.TTkLog.debug('test')
|
||||||
|
# print(v.text())
|
||||||
|
|
||||||
|
artist_name = v.text()
|
||||||
|
for artist in self.artists:
|
||||||
|
if artist.name == artist_name:
|
||||||
|
self.selected_artist = artist
|
||||||
|
|
||||||
|
self._clearAlbums()
|
||||||
|
self._clearSongs()
|
||||||
|
albums = conn.getArtistAlbums(self.selected_artist.id)
|
||||||
|
self.albumList.addItems([album.name for album in albums])
|
||||||
|
|
||||||
|
@ttk.pyTTkSlot(ttk.TTkWidgets.listwidget.TTkAbstractListItem)
|
||||||
|
def clickAlbum(self, v: ttk.TTkWidgets.listwidget.TTkAbstractListItem):
|
||||||
|
|
||||||
|
album_name = v.text()
|
||||||
|
|
||||||
|
albums = conn.getArtistAlbums(self.selected_artist.id)
|
||||||
|
for album in albums:
|
||||||
|
if album.title == album_name:
|
||||||
|
self.selected_album = album
|
||||||
|
|
||||||
|
# print('b')
|
||||||
|
|
||||||
|
self._clearSongs()
|
||||||
|
self.songList.addItems([song.title for song in conn.getAlbumSongs(self.selected_album.id)])
|
||||||
|
|
||||||
|
|
||||||
|
conn = SubSonic.SubpyConn(u, p, "https://music.0x01fe.net")
|
||||||
|
player = SubPlayer(conn)
|
||||||
|
player.run()
|
||||||
Reference in new issue
Block a user