From c4cba2af4e513c8f6dc7b629fd7b657b4a4cf85f Mon Sep 17 00:00:00 2001 From: JISAUAY Date: Fri, 24 Jan 2025 13:31:02 -0600 Subject: [PATCH] working on a queue for the main screen --- requirements.txt | 6 ++---- screens-test.py | 49 +++++++++++++++++++++++++++++++++++++++--------- textual.log | 8 ++++++-- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2f95170..c6e8c42 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,3 @@ requests==2.31.0 -simpleaudio==1.0.4 -urwid==2.6.16 -py-sonic==1.0.1 -pyTermTk==0.41.0a54 \ No newline at end of file +textual==1.0.0 +pygame==2.6.0 \ No newline at end of file diff --git a/screens-test.py b/screens-test.py index f344e73..c080ddf 100644 --- a/screens-test.py +++ b/screens-test.py @@ -19,6 +19,7 @@ import pygame from textual import on, events from textual.app import App, ComposeResult from textual.widgets import Footer, Header, OptionList, DataTable, ProgressBar, Label +from textual.containers import Horizontal, Vertical from textual.screen import Screen from textual.widgets.option_list import Option @@ -201,7 +202,7 @@ class PlaylistSongs(Screen): BINDINGS = [ ('escape', 'die()', "Back"), ('p', 'play()', 'Play Song'), - ('q' 'queue()', 'Queue Song') + ('q', 'queue()', 'Queue Song') ] selected_song_id: str | None = None @@ -281,12 +282,16 @@ class TextualSubpyPlayer(App): currently_playing: SubSonic.Song | None = None song_queue: list[SubSonic.Song] = [] - playing: bool = False + isPlaying: bool = False place: int = 0 def compose(self) -> ComposeResult: - yield Label() - yield ProgressBar() + yield Header(icon="") + with Horizontal(): + with Vertical(classes="column"): + yield Label(id="playing") + yield ProgressBar() + yield DataTable() yield Footer() def on_mount(self) -> None: @@ -297,21 +302,47 @@ class TextualSubpyPlayer(App): self.install_screen(Favourites(), name="favourites") self.install_screen(Playlists(), name="playlists") + queueTable: DataTable = self.query_one(DataTable) + queueTable.cursor_type = "row" + queueTable.add_columns("Title", "Album", "Artist", "Plays", "Duration", "Bitrate") + def on_key(self, event: events.Key) -> None: # logging.debug(f'Key Pressed {event.name}') pass + @on(events.ScreenSuspend) + def sus(self, event: events.ScreenSuspend) -> None: + logging.debug('sus') + + def on_screen_suspend(self, event: events.ScreenSuspend) -> None: + logging.debug('sus3') + + @on(events.ScreenResume) + def screen_resumed(self, event: events.ScreenResume) -> None: + logging.debug('Main screen resumed') + queueTable: DataTable = self.query_one(DataTable) + for row_key, row in queueTable.rows.items(): + queueTable.remove_row(row_key) + + for song in self.song_queue: + queueTable.add_row(song.title, song.album, song.artist, song.playCount, song.duration, song.bitRate) + def play_song(self, song: SubSonic.Song) -> None: self.currently_playing = song - self.playing = True + self.isPlaying = True logging.debug(f"Playing song {song.title} by {song.artist}.") + self.notify(f"Playing \"{song.title}\" by {song.artist}.") + r = conn.stream(song.id) audio_data = io.BytesIO(r.content) pygame.mixer.music.load(audio_data) pygame.mixer.music.play() + # playingLabel: Label = self.query_one(Label) + # playingLabel. + # Set callback loop for progress bar # self.progress_timer = self.set_interval(1 / 10, self.update_progress, pause=False) @@ -329,13 +360,13 @@ class TextualSubpyPlayer(App): if not self.currently_playing: return None - if self.playing: + if self.isPlaying: self.place = pygame.mixer.music.get_pos() pygame.mixer.music.pause() - self.playing = False + self.isPlaying = False else: - pygame.mixer.music.play(start=self.place) - self.playing = True + pygame.mixer.music.unpause() + self.isPlaying = True if __name__ == '__main__': app = TextualSubpyPlayer() diff --git a/textual.log b/textual.log index 41a1db9..005a5e5 100644 --- a/textual.log +++ b/textual.log @@ -1,2 +1,6 @@ -[2025-01-24 12:00:51,019] DEBUG in proactor_events: Using proactor: IocpProactor -[2025-01-24 12:00:51,225] DEBUG in screens-test: mount called +[2025-01-24 13:28:35,298] DEBUG in selector_events: Using selector: EpollSelector +[2025-01-24 13:28:35,327] DEBUG in screens-test: mount called +[2025-01-24 13:28:36,853] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 +[2025-01-24 13:28:37,082] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getIndexes?u=pseudo&t=af331bf0765ef34694c1b437cd1be620&s=QURWEGZ9&v=1.16.1&c=testing HTTP/1.1" 200 None +[2025-01-24 13:28:39,679] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 +[2025-01-24 13:28:39,872] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getMusicDirectory?u=pseudo&t=ed6bdeb43a72d180720f3cb2091dfb5b&s=0AUHHE1K&v=1.16.1&c=testing&id=0371f111b9d8391a4b669a4199809186 HTTP/1.1" 200 983