working on a queue for the main screen

This commit is contained in:
JISAUAY committed 2025-01-24 13:31:02 -06:00
1 parent 3eab7260e6
commit c4cba2af4e
3 files changed
+48 -15

No files matched your search

+2 -4
View File
@@ -1,5 +1,3 @@
requests==2.31.0 requests==2.31.0
simpleaudio==1.0.4 textual==1.0.0
urwid==2.6.16 pygame==2.6.0
py-sonic==1.0.1
pyTermTk==0.41.0a54
+40 -9
View File
@@ -19,6 +19,7 @@ import pygame
from textual import on, events from textual import on, events
from textual.app import App, ComposeResult from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList, DataTable, ProgressBar, Label from textual.widgets import Footer, Header, OptionList, DataTable, ProgressBar, Label
from textual.containers import Horizontal, Vertical
from textual.screen import Screen from textual.screen import Screen
from textual.widgets.option_list import Option from textual.widgets.option_list import Option
@@ -201,7 +202,7 @@ class PlaylistSongs(Screen):
BINDINGS = [ BINDINGS = [
('escape', 'die()', "Back"), ('escape', 'die()', "Back"),
('p', 'play()', 'Play Song'), ('p', 'play()', 'Play Song'),
('q' 'queue()', 'Queue Song') ('q', 'queue()', 'Queue Song')
] ]
selected_song_id: str | None = None selected_song_id: str | None = None
@@ -281,12 +282,16 @@ class TextualSubpyPlayer(App):
currently_playing: SubSonic.Song | None = None currently_playing: SubSonic.Song | None = None
song_queue: list[SubSonic.Song] = [] song_queue: list[SubSonic.Song] = []
playing: bool = False isPlaying: bool = False
place: int = 0 place: int = 0
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Label() yield Header(icon="")
yield ProgressBar() with Horizontal():
with Vertical(classes="column"):
yield Label(id="playing")
yield ProgressBar()
yield DataTable()
yield Footer() yield Footer()
def on_mount(self) -> None: def on_mount(self) -> None:
@@ -297,21 +302,47 @@ class TextualSubpyPlayer(App):
self.install_screen(Favourites(), name="favourites") self.install_screen(Favourites(), name="favourites")
self.install_screen(Playlists(), name="playlists") 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: def on_key(self, event: events.Key) -> None:
# logging.debug(f'Key Pressed {event.name}') # logging.debug(f'Key Pressed {event.name}')
pass 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: def play_song(self, song: SubSonic.Song) -> None:
self.currently_playing = song self.currently_playing = song
self.playing = True self.isPlaying = True
logging.debug(f"Playing song {song.title} by {song.artist}.") logging.debug(f"Playing song {song.title} by {song.artist}.")
self.notify(f"Playing \"{song.title}\" by {song.artist}.")
r = conn.stream(song.id) r = conn.stream(song.id)
audio_data = io.BytesIO(r.content) audio_data = io.BytesIO(r.content)
pygame.mixer.music.load(audio_data) pygame.mixer.music.load(audio_data)
pygame.mixer.music.play() pygame.mixer.music.play()
# playingLabel: Label = self.query_one(Label)
# playingLabel.
# Set callback loop for progress bar # Set callback loop for progress bar
# self.progress_timer = self.set_interval(1 / 10, self.update_progress, pause=False) # 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: if not self.currently_playing:
return None return None
if self.playing: if self.isPlaying:
self.place = pygame.mixer.music.get_pos() self.place = pygame.mixer.music.get_pos()
pygame.mixer.music.pause() pygame.mixer.music.pause()
self.playing = False self.isPlaying = False
else: else:
pygame.mixer.music.play(start=self.place) pygame.mixer.music.unpause()
self.playing = True self.isPlaying = True
if __name__ == '__main__': if __name__ == '__main__':
app = TextualSubpyPlayer() app = TextualSubpyPlayer()
+6 -2
View File
@@ -1,2 +1,6 @@
[2025-01-24 12:00:51,019] DEBUG in proactor_events: Using proactor: IocpProactor [2025-01-24 13:28:35,298] DEBUG in selector_events: Using selector: EpollSelector
[2025-01-24 12:00:51,225] DEBUG in screens-test: mount called [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