From 1d56b5efea2ccf3bb0272f40f26a60f3937b5216 Mon Sep 17 00:00:00 2001 From: 0x01FE Date: Thu, 23 Jan 2025 12:14:38 -0600 Subject: [PATCH] stuff working more --- SubSonic.py | 14 ++++- main.py | 4 +- screens-test.py | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ textual-test.py | 2 - textual.log | 11 +--- 5 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 screens-test.py diff --git a/SubSonic.py b/SubSonic.py index 5eddd07..912f60c 100644 --- a/SubSonic.py +++ b/SubSonic.py @@ -177,7 +177,7 @@ class SubpyConn: return ArtistIndexes(requests.get(url + self._encodePayload(self._getBasePayload())).content) def _getMusicDirectory(self, id: str): - url = 'https://' + self.base_url + '/rest/getMusicDirectory?' + url = self.base_url + '/rest/getMusicDirectory?' payload = self._getBasePayload() payload['id'] = id @@ -230,6 +230,18 @@ class SubpyConn: return artists + def getAlbums(self) -> list[Album]: + url = self.base_url + '/rest/getAlbumList?' + + payload = self._getBasePayload() + payload['type'] = 'alphabeticalByName' + payload['size'] = 20 + + r = requests.get(url + self._encodePayload(payload)) + + with open("albumList.xml" , 'wb') as file: + file.write(r.content) + # Returns a requests Response object, the data stream can be found in Response.content def stream(self, song_id: str) -> requests.Response: url = self.base_url + '/rest/stream?' diff --git a/main.py b/main.py index 9fd44d5..a3a2724 100644 --- a/main.py +++ b/main.py @@ -89,7 +89,9 @@ class SubPyPlayer: def exit_program(self, button: urwid.Button) -> None: raise urwid.ExitMainLoop() -player = SubPyPlayer(conn) +# player = SubPyPlayer(conn) + +conn.getAlbums() # player.play_song(echidna_id) diff --git a/screens-test.py b/screens-test.py new file mode 100644 index 0000000..ccacb90 --- /dev/null +++ b/screens-test.py @@ -0,0 +1,142 @@ +import logging +import os + +from enum import Enum + +LOG_FILE = 'textual.log' +LOGGING_LEVEL = logging.DEBUG +LOG_FORMAT = '[%(asctime)s] %(levelname)s in %(module)s: %(message)s' + +# Clear Log File +os.remove(LOG_FILE) + +logging.basicConfig(filename=LOG_FILE, level=LOGGING_LEVEL, format=LOG_FORMAT) + +import SubSonic + + +from textual import on, events +from textual.app import App, ComposeResult +from textual.widgets import Footer, Header, OptionList, DataTable, Tabs, Tab, TabbedContent, TabPane +from textual.screen import Screen +from textual.widgets.option_list import Option + +u = 'pseudo' +p = 'telegram9dock-MICHEL' + +conn = SubSonic.SubpyConn(u, p, "https://music.0x01fe.net") + +class AlbumSongs(Screen): + BINDINGS = [ + ('escape', 'die()', "Back") + ] + + def __init__(self, album_id: str): + self.album_id = album_id + super().__init__() + + def compose(self) -> ComposeResult: + yield DataTable(id="albumSongs") + yield Footer() + + def on_mount(self) -> None: + songs = conn.getAlbumSongs(self.album_id) + songsTable: DataTable = self.query_one(DataTable) + + songsTable.cursor_type = 'row' + songsTable.add_columns("#", "Title", "Artist", "Duration", "Bitrate") + + for song in songs: + songsTable.add_row(song.trackNumber, song.title, song.artist, song.duration, song.bitRate, key=song.id) + + + # Pops and uninstalls self + def action_die(self) -> None: + app.pop_screen() + app.uninstall_screen("albumSongs") + +class ArtistAlbums(Screen): + BINDINGS = [ + ('escape', 'die()', "Back") + ] + + def __init__(self, artist_id: str): + self.artist_id = artist_id + super().__init__() + + def compose(self) -> ComposeResult: + yield DataTable(id="Albums") + yield Footer() + + def on_mount(self) -> None: + albums = conn.getArtistAlbums(self.artist_id) + albumTable: DataTable = self.query_one(DataTable) + + albumTable.cursor_type = 'row' + + albumTable.add_columns("Title", "Songs") + + for album in albums: + albumTable.add_row(album.title, album.songCount, key=album.id) + + @on(DataTable.RowSelected) + async def album_selected(self, event: DataTable.RowSelected) -> None: + app.install_screen(AlbumSongs(event.row_key.value), "albumSongs") + app.push_screen("albumSongs") + + # Pops and uninstalls self + def action_die(self) -> None: + app.pop_screen() + app.uninstall_screen("artistAlbums") + +class Artists(Screen): + BINDINGS = [ + ('escape', 'app.pop_screen', "Back") + ] + + def compose(self) -> ComposeResult: + yield OptionList(id="Artists") + yield Footer() + + def on_mount(self) -> None: + artists = conn.getArtists() + artistList = self.query_one(OptionList) + + for artist in artists: + artistList.add_option(Option(artist.name, artist.id)) + + @on(OptionList.OptionSelected) + def artist_selected(self, event: OptionList.OptionSelected) -> None: + app.install_screen(ArtistAlbums(event.option_id), 'artistAlbums') + app.push_screen('artistAlbums') + +class Albums(Screen): + BINDINGS = [ + ('escape', 'app.pop_screen', "Back") + ] + + def compose(self) -> ComposeResult: + yield DataTable() + yield Footer() + + def on_mount(self) -> None: + albums = conn.getAlbums() + +class TextualSubpyPlayer(App): + BINDINGS = [ + ("f1", "push_screen('artists')", "Artists"), + ("f2", "push_screen('albums')", "Albums") + ] + + def compose(self) -> ComposeResult: + yield Footer() + + def on_mount(self) -> None: + self.install_screen(Artists(), name="artists") + + def on_key(self, event: events.Key) -> None: + logging.debug(f'Key Pressed {event.name}') + +if __name__ == '__main__': + app = TextualSubpyPlayer() + app.run() diff --git a/textual-test.py b/textual-test.py index 6391def..6759ce6 100644 --- a/textual-test.py +++ b/textual-test.py @@ -23,8 +23,6 @@ from textual.widgets.option_list import Option u = 'pseudo' p = 'telegram9dock-MICHEL' -conn = SubSonic.SubpyConn(u, p, "music.0x01fe.net") - class Menus(Enum): MAIN = "MAIN" ARTISTS = "Artists" diff --git a/textual.log b/textual.log index c74633b..4795f95 100644 --- a/textual.log +++ b/textual.log @@ -1,10 +1 @@ -[2025-01-23 11:19:08,906] DEBUG in selector_events: Using selector: EpollSelector -[2025-01-23 11:19:08,964] DEBUG in textual-test: Artists tab selected -[2025-01-23 11:19:08,966] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 -[2025-01-23 11:19:09,267] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getIndexes?u=pseudo&t=dff0ee3a818ed4cd4b15e1d30972b9de&s=419LM0NL&v=1.16.1&c=testing HTTP/1.1" 200 None -[2025-01-23 11:19:10,298] DEBUG in textual-test: Key Pressed right -[2025-01-23 11:19:10,307] DEBUG in textual-test: Albums tab selected -[2025-01-23 11:19:11,009] DEBUG in textual-test: Key Pressed left -[2025-01-23 11:19:11,015] DEBUG in textual-test: Artists tab selected -[2025-01-23 11:19:11,017] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 -[2025-01-23 11:19:11,338] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getIndexes?u=pseudo&t=df38529ec337b09026c038ea4ed94b26&s=C0ADXZ3M&v=1.16.1&c=testing HTTP/1.1" 200 None +[2025-01-23 12:06:54,543] DEBUG in selector_events: Using selector: EpollSelector