idk
This commit is contained in:
1 parent
6854b4ddd9
commit
00d66f7258
1 file changed
+13
-21
+13
-21
@@ -85,42 +85,34 @@ 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)
|
||||
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}")
|
||||
|
||||
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))
|
||||
|
||||
@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)
|
||||
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}")
|
||||
|
||||
def populate_songs(self, songs: list[SubSonic.Song]) -> None:
|
||||
table = self.query_one("#songs", DataTable)
|
||||
table.clear()
|
||||
for song in songs:
|
||||
table.add_row(song.trackNumber, song.title, song.artist, song.album, key=song.id)
|
||||
|
||||
@on(DataTable.RowSelected)
|
||||
def on_song_selected(self, event: DataTable.RowSelected) -> None:
|
||||
song_id = event.row_key.value
|
||||
|
||||
Reference in new issue
Block a user