subclient

Subsonic ncurses client
git clone https://git.e1e0.net/subclient.git
Log | Files | Refs | README

commit 50af085602db397ed8d18faa10585618dd0a99c2
parent 0c1405474c4b9fbfc6a1cbb97c9b24a864da732e
Author: Paco Esteban <paco@e1e0.net>
Date:   Sun, 20 Jun 2021 17:46:14 +0200

make play next in playlist. lots of errors still

Diffstat:
Msubclient/playback.py | 6+++++-
Msubclient/subclient.py | 27+++++++++++++++++++--------
2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/subclient/playback.py b/subclient/playback.py @@ -7,7 +7,7 @@ class Player: self.player = MPV(ipc_socket='/tmp/subclient-mpv-socket', audio_display='no') - def play(self, stream): + def play(self, stream, callback): with tempfile.NamedTemporaryFile() as fp: while True: chunk = stream.read(512*1024) @@ -17,6 +17,7 @@ class Player: fp.seek(0) self.player.play(fp.name) self.player.wait_for_property('eof-reached') + self.player.bind_event('end-file', callback) def exit(self): self.player.terminate() @@ -24,6 +25,9 @@ class Player: def is_paused(self): return self.player.pause + def is_idle(self): + return self.player.core_idle + def set_pause(self, state): self.player.pause = state diff --git a/subclient/subclient.py b/subclient/subclient.py @@ -35,8 +35,6 @@ class SubClient: self.playlist = [] self.what = 0 - self.master.run_on_exit(self.player.exit) - self.master.add_key_command(py_cui.keys.KEY_SPACE, self.pause) # The scrolled list cells that will contain our tasks in each of the # three categories @@ -116,11 +114,14 @@ class SubClient: self.nav_scroll_cell.add_item_list(items) def play_from_here(self): - self.update_playlist() - self.play_song() + if self.what == 2: + self.current_song = self.nav_scroll_cell.get() + self.update_playlist() + self.play_song() + else: + self._nav_forward() def update_playlist(self): - self.current_song = self.nav_scroll_cell.get() self.playlist = self.curr_album_songs[ self.curr_album_songs.index(self.current_song):] self.play_scroll_cell.clear() @@ -129,9 +130,16 @@ class SubClient: def play_song(self): self._now_playing('Now Playing', self.playlist[0]) stream = self.subsonic.get_song_stream(self.playlist[0]) - del self.playlist[0] - self.player.stop() - self.player.play(stream) + if not self.player.is_idle(): + self.player.stop() + self.player.play(stream, self.next_song) + + def next_song(self, event): + if len(self.playlist) > 0: + del self.playlist[0] + self.current_song = self.playlist[0] + self.update_playlist() + self.play_song() def pause(self): paused = self.player.is_paused() @@ -199,6 +207,9 @@ class SubClient: self.update_nav() def quit(self): + if self.player.is_idle(): + self.player.stop() + self.player.exit() self.master.stop()