85 lines
1.5 KiB
Python
85 lines
1.5 KiB
Python
import random
|
|
import string
|
|
import hashlib
|
|
import urllib.parse
|
|
|
|
import xml.etree
|
|
import xml.etree.ElementTree
|
|
|
|
import requests
|
|
|
|
|
|
u = 'pseudo'
|
|
p = 'telegram9dock-MICHEL'
|
|
|
|
|
|
def saltGenerator() -> str:
|
|
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(8))
|
|
|
|
salt = saltGenerator()
|
|
t = hashlib.md5((p + salt).encode('utf-8')).hexdigest()
|
|
|
|
payload = {
|
|
"u" : u,
|
|
"t" : t,
|
|
"s" : salt,
|
|
"v" : '1.16.1',
|
|
"c" : 'testing'
|
|
}
|
|
|
|
url = 'https://music.0x01fe.net/rest/getArtists?'
|
|
|
|
url = url + urllib.parse.urlencode(payload, quote_via=urllib.parse.quote_plus)
|
|
|
|
# print(url)
|
|
# response = requests.get(url)
|
|
|
|
# with open("artist_response.xml", 'wb') as file:
|
|
# file.write(response.content)
|
|
|
|
|
|
|
|
class Artist:
|
|
|
|
id: str
|
|
imageUrl: str
|
|
name: str
|
|
albumCount: int
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def fromDict(self, d: dict):
|
|
self.id = d['id']
|
|
self.imageUrl = d['artistImageUrl']
|
|
self.name = d['name']
|
|
self.albumCount = d['albumCount']
|
|
|
|
def getArtists() -> list[Artist]:
|
|
tree = xml.etree.ElementTree.parse("artist_response.xml")
|
|
root = tree.getroot()
|
|
|
|
artists: list[Artist] = []
|
|
|
|
if root.get('status') != 'ok':
|
|
return []
|
|
|
|
for item in root.iter():
|
|
print(item.tag, dict(item.items()))
|
|
|
|
if item.tag == '{http://subsonic.org/restapi}artist':
|
|
a = Artist()
|
|
a.fromDict(dict(item.items()))
|
|
|
|
artists.append(a)
|
|
|
|
|
|
|
|
return artists
|
|
|
|
artists = getArtists()
|
|
|
|
for artist in artists:
|
|
print(artist.name)
|
|
|