idk
This commit is contained in:
1 parent
6854b4ddd9
commit
00d66f7258
1 file changed
+14
-22
+14
-22
@@ -85,42 +85,34 @@ 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)
|
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:
|
except Exception as e:
|
||||||
logging.error(f"Failed to get playlists: {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)
|
@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)
|
||||||
|
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:
|
except Exception as e:
|
||||||
logging.error(f"Failed to get playlist songs: {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)
|
@on(DataTable.RowSelected)
|
||||||
def on_song_selected(self, event: DataTable.RowSelected) -> None:
|
def on_song_selected(self, event: DataTable.RowSelected) -> None:
|
||||||
song_id = event.row_key.value
|
song_id = event.row_key.value
|
||||||
@@ -133,7 +125,7 @@ class MusicApp(App):
|
|||||||
song = conn.getSong(song_id)
|
song = conn.getSong(song_id)
|
||||||
now_playing = self.query_one(NowPlaying)
|
now_playing = self.query_one(NowPlaying)
|
||||||
self.call_from_thread(setattr, now_playing, "song", song)
|
self.call_from_thread(setattr, now_playing, "song", song)
|
||||||
|
|
||||||
stream_data = conn.stream(song_id)
|
stream_data = conn.stream(song_id)
|
||||||
pygame.mixer.music.load(io.BytesIO(stream_data.content))
|
pygame.mixer.music.load(io.BytesIO(stream_data.content))
|
||||||
pygame.mixer.music.play()
|
pygame.mixer.music.play()
|
||||||
|
|||||||
Reference in new issue
Block a user