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() yield Footer()
def on_mount(self) -> None: def on_mount(self) -> None:
self.get_playlists() self.run_worker(self.get_playlists(), exclusive=True)
table = self.query_one(DataTable) table = self.query_one(DataTable)
table.add_columns("Track", "Title", "Artist", "Album") table.add_columns("Track", "Title", "Artist", "Album")
async def get_playlists(self) -> None:
@work(exclusive=True, thread=True)
def get_playlists(self) -> None:
try: try:
playlists = conn.getPlaylists() 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) option_list = self.query_one("#playlists", OptionList)
for playlist in playlists: for playlist in playlists:
option_list.add_option(Option(playlist.name, id=playlist.id)) 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) @on(OptionList.OptionSelected)
def on_playlist_selected(self, event: OptionList.OptionSelected) -> None: async def on_playlist_selected(self, event: OptionList.OptionSelected) -> None:
self.get_playlist_songs(event.option.id) self.run_worker(self.get_playlist_songs(event.option.id), exclusive=True)
@work(exclusive=True, thread=True) async def get_playlist_songs(self, playlist_id: str) -> None:
def get_playlist_songs(self, playlist_id: str) -> None:
try: try:
songs = conn.getPlaylist(playlist_id) songs = conn.getPlaylist(playlist_id)
self.call_from_thread(self.populate_songs, songs) table = self.query_one(DataTable)
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.clear() table.clear()
logging.debug([song.title for song in songs])
for song in songs: for song in songs:
table.add_row(song.trackNumber, song.title, song.artist, song.album, key=song.id) 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) @on(DataTable.RowSelected)
def on_song_selected(self, event: DataTable.RowSelected) -> None: def on_song_selected(self, event: DataTable.RowSelected) -> None: