more pytermtk stuff added

This commit is contained in:
0x01FE committed 2025-01-17 14:46:58 -06:00
1 parent c0986f8d2d
commit cb01fa2aee
3 files changed
+138 -94

No files matched your search

+77 -67
View File
@@ -16,72 +16,6 @@ import requests
# u = 'pseudo'
# 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:
id: str
title: str
@@ -138,6 +72,73 @@ class Song:
self.channelCount = int(song_info['channelCount'])
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:
username: str
password: str
@@ -205,14 +206,23 @@ class SubpyConn:
r: requests.Response = self._getMusicDirectory(album_id)
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] = []
if root.get('status') != 'ok':
return []
for item in root.iter():
if item.tag == '{http://subsonic.org/restapi}child':
songs.append(Song(dict(item.items())))
for song in songs:
print(song.title)
return songs
def getArtists(self) -> list[Artist]:
+1
View File
@@ -2,3 +2,4 @@ requests==2.31.0
simpleaudio==1.0.4
urwid==2.6.16
py-sonic==1.0.1
pyTermTk==0.41.0a54
+60 -27
View File
@@ -4,50 +4,83 @@ import SubSonic
u = 'pseudo'
p = 'telegram9dock-MICHEL'
conn = SubSonic.SubpyConn(u, p, "https://music.0x01fe.net")
echidna_id = "937004317800a879f0cddd471fb82387"
class SubPlayer:
conn: SubSonic.SubpyConn
artists = conn.getArtists()
selected_artist = None
artists: list[SubSonic.Artist]
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')
# artistMenu = ttk.TTkMenu(title="Artists", parent=root, border=True, size=(100, 30))
# for artist in artists:
# newButton = ttk.TTkMenuButton(text=artist.name, parent=artistMenu)
# artistMenu.addMenuItem(newButton)
def run(self) -> None:
self.artists = conn.getArtists()
self.root = ttk.TTk(layout=ttk.TTkHBoxLayout())
artistList = ttk.TTkList(
self.artistList = ttk.TTkList(
name="Artists",
parent=root,
items=[artist.name for artist in artists]
)
parent=self.root,
items=[artist.name for artist in self.artists]
)
albumList = ttk.TTkList(
self.albumList = ttk.TTkList(
name="ArtistAlbums",
parent=root
)
parent=self.root
)
@ttk.pyTTkSlot(ttk.TTkWidgets.listwidget.TTkAbstractListItem)
def clickArtist(v: ttk.TTkWidgets.listwidget.TTkAbstractListItem):
self.songList = ttk.TTkList(
name="AlbumSongs",
parent=self.root
)
self.artistList.itemClicked.connect(self.clickArtist)
self.albumList.itemClicked.connect(self.clickAlbum)
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 artists:
for artist in self.artists:
if artist.name == artist_name:
selected_artist = artist.id
self.selected_artist = artist
albumList.removeItems(albumList.items())
albumList.addItems([album.name for album in conn.getArtistAlbums(selected_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)])
artistList.itemClicked.connect(clickArtist)
root.mainloop()
conn = SubSonic.SubpyConn(u, p, "https://music.0x01fe.net")
player = SubPlayer(conn)
player.run()