66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
import xml.etree.ElementTree
|
|
|
|
import Artist
|
|
|
|
|
|
class ArtistIndex:
|
|
name: str
|
|
artists: list[Artist.Artist]
|
|
|
|
def __init__(self, indexInfo: dict, artists: list[dict]):
|
|
self.name = indexInfo['name']
|
|
|
|
self.artists = []
|
|
for artist in artists:
|
|
self.artists.append(Artist.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()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|