quite a bit of stuff
This commit is contained in:
1 parent
41f6690937
commit
d3b5a2120f
6 files changed
+283
-99
No files matched your search
+9
-99
@@ -1,20 +1,17 @@
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import logging
|
||||
import urllib.parse
|
||||
# import time
|
||||
|
||||
import xml.etree
|
||||
import xml.etree.ElementTree
|
||||
|
||||
import requests
|
||||
# import libsonic
|
||||
# import simpleaudio
|
||||
# import pyaudio
|
||||
|
||||
|
||||
# u = 'pseudo'
|
||||
# p = 'telegram9dock-MICHEL'
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Album:
|
||||
id: str
|
||||
@@ -65,7 +62,7 @@ class Song:
|
||||
self.duration = int(song_info['duration'])
|
||||
self.bitRate = int(song_info['bitRate'])
|
||||
self.path = song_info['path']
|
||||
self.discNumber = int(song_info['discNumber'])
|
||||
self.discNumber = int(song_info['discNumber']) if 'discNumber' in song_info else None
|
||||
self.albumId = song_info['albumId']
|
||||
self.artistId = song_info['artistId']
|
||||
self.comment = song_info['comment']
|
||||
@@ -180,7 +177,7 @@ class SubpyConn:
|
||||
return ArtistIndexes(requests.get(url + self._encodePayload(self._getBasePayload())).content)
|
||||
|
||||
def _getMusicDirectory(self, id: str):
|
||||
url = self.base_url + '/rest/getMusicDirectory?'
|
||||
url = 'https://' + self.base_url + '/rest/getMusicDirectory?'
|
||||
|
||||
payload = self._getBasePayload()
|
||||
payload['id'] = id
|
||||
@@ -195,8 +192,6 @@ class SubpyConn:
|
||||
albums: list[Album] = []
|
||||
|
||||
for item in root.iter():
|
||||
# print(item.tag, dict(item.items()))
|
||||
|
||||
if item.tag == '{http://subsonic.org/restapi}child':
|
||||
albums.append(Album(dict(item.items())))
|
||||
|
||||
@@ -204,6 +199,9 @@ class SubpyConn:
|
||||
|
||||
def getAlbumSongs(self, album_id: str) -> list[Song]:
|
||||
r: requests.Response = self._getMusicDirectory(album_id)
|
||||
logger.debug(f"Requesting all songs for album {album_id} using url {self.base_url}")
|
||||
logger.debug(f'Got response with status code {r.status_code}')
|
||||
|
||||
xml_data: str = r.content.decode('utf-8')
|
||||
|
||||
if r.status_code != 200:
|
||||
@@ -212,6 +210,7 @@ class SubpyConn:
|
||||
root: xml.etree.ElementTree.Element = xml.etree.ElementTree.fromstring(xml_data)
|
||||
songs: list[Song] = []
|
||||
|
||||
logger.debug(f"Request Status: {root.get('status')}")
|
||||
if root.get('status') != 'ok':
|
||||
return []
|
||||
|
||||
@@ -257,92 +256,3 @@ class SubpyConn:
|
||||
if item.tag == '{http://subsonic.org/restapi}song':
|
||||
return Song(dict(item.items()))
|
||||
|
||||
# conn = SubpyConn(u, p, "https://music.0x01fe.net")
|
||||
|
||||
|
||||
|
||||
# artistIndexes = conn.getIndexes()
|
||||
# for artistIndex in artistIndexes.indexes:
|
||||
# print(artistIndex.name, artistIndex.artists)
|
||||
|
||||
helios_id = 'c69cdc593487ed813f1e11ecb270b228'
|
||||
yakui_id = "7f6ca9951af294420382442061a2d6ee"
|
||||
# r = conn.getMusicDirectory(helios_id)
|
||||
# with open("getHelios.xml", 'wb') as file:
|
||||
# file.write(r.content)
|
||||
|
||||
# yakui_albums = conn.getArtistAlbums(yakui_id)
|
||||
|
||||
# for album in yakui_albums:
|
||||
# print(album.name)
|
||||
|
||||
# helios_songs = conn.getAlbumSongs(helios_id)
|
||||
# for song in helios_songs:
|
||||
# print(song.trackNumber, song.title)
|
||||
|
||||
# artists = conn.getArtists()
|
||||
|
||||
# for artist in artists:
|
||||
# print(artist.name)
|
||||
|
||||
echidna_id = "937004317800a879f0cddd471fb82387"
|
||||
|
||||
# print(conn.stream(echidna_id).content)
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
# conn = libsonic.Connection('https://music.0x01fe.net', 'pseudo', p, port=443)
|
||||
|
||||
|
||||
# song = conn.getRandomSongs(1)['randomSongs']['song'][0]
|
||||
# song_id = song['id']
|
||||
# rate = song['samplingRate']
|
||||
|
||||
# print(song_id)
|
||||
|
||||
# stream = conn.stream(song_id)
|
||||
|
||||
# while not stream.fp:
|
||||
# pass
|
||||
|
||||
|
||||
# pya = pyaudio.PyAudio()
|
||||
# pya_stream = pya.open(format=)
|
||||
# wave_obj = simpleaudio.WaveObject(stream.fp)
|
||||
# play_obj = wave_obj.play()
|
||||
# play_obj.wait_done()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user