more pytermtk stuff added
This commit is contained in:
1 parent
c0986f8d2d
commit
cb01fa2aee
3 files changed
+145
-101
No files matched your search
+77
-67
@@ -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]:
|
||||
|
||||
Reference in new issue
Block a user