This commit is contained in:
JISAUAY committed 2025-09-03 14:28:13 -05:00
1 parent 6854b4ddd9
commit 00d66f7258
1 file changed
+11 -19
+11 -19
View File
@@ -85,41 +85,33 @@ class MusicApp(App):
yield Footer()
def on_mount(self) -> None:
self.get_playlists()
self.run_worker(self.get_playlists(), exclusive=True)
table = self.query_one(DataTable)
table.add_columns("Track", "Title", "Artist", "Album")
@work(exclusive=True, thread=True)
def get_playlists(self) -> None:
async def get_playlists(self) -> None:
try:
playlists = conn.getPlaylists()
self.call_from_thread(self.populate_playlists, playlists)
except Exception as e:
logging.error(f"Failed to get playlists: {e}")
def populate_playlists(self, playlists: list[SubSonic.Playlist]) -> None:
option_list = self.query_one("#playlists", OptionList)
for playlist in playlists:
option_list.add_option(Option(playlist.name, id=playlist.id))
except Exception as e:
logging.error(f"Failed to get playlists: {e}")
@on(OptionList.OptionSelected)
def on_playlist_selected(self, event: OptionList.OptionSelected) -> None:
self.get_playlist_songs(event.option.id)
async def on_playlist_selected(self, event: OptionList.OptionSelected) -> None:
self.run_worker(self.get_playlist_songs(event.option.id), exclusive=True)
@work(exclusive=True, thread=True)
def get_playlist_songs(self, playlist_id: str) -> None:
async def get_playlist_songs(self, playlist_id: str) -> None:
try:
songs = conn.getPlaylist(playlist_id)
self.call_from_thread(self.populate_songs, songs)
except Exception as e:
logging.error(f"Failed to get playlist songs: {e}")
def populate_songs(self, songs: list[SubSonic.Song]) -> None:
table = self.query_one("#songs", DataTable)
table = self.query_one(DataTable)
table.clear()
logging.debug([song.title for song in songs])
for song in songs:
table.add_row(song.trackNumber, song.title, song.artist, song.album, key=song.id)
except Exception as e:
logging.error(f"Failed to get playlist songs: {e}")
@on(DataTable.RowSelected)
def on_song_selected(self, event: DataTable.RowSelected) -> None: