commit 0c1405474c4b9fbfc6a1cbb97c9b24a864da732e
parent 218453048fdfe582abb5461eb397f01ef869c3a9
Author: Paco Esteban <paco@e1e0.net>
Date: Sun, 20 Jun 2021 17:44:51 +0200
implement seek and better now playing method
Diffstat:
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/subclient/playback.py b/subclient/playback.py
@@ -29,3 +29,6 @@ class Player:
def stop(self):
self.player.command('stop')
+
+ def seek(self, duration='+5'):
+ self.player.command('seek', duration)
diff --git a/subclient/subclient.py b/subclient/subclient.py
@@ -68,6 +68,14 @@ class SubClient:
self._nav_top)
self.nav_scroll_cell.add_key_command(py_cui.keys.KEY_G_UPPER,
self._nav_bottom)
+ self.nav_scroll_cell.add_key_command(py_cui.keys.KEY_F_LOWER,
+ self.song_seek_fwd_short)
+ self.nav_scroll_cell.add_key_command(py_cui.keys.KEY_F_UPPER,
+ self.song_seek_fwd_long)
+ self.nav_scroll_cell.add_key_command(py_cui.keys.KEY_B_LOWER,
+ self.song_seek_bck_short)
+ self.nav_scroll_cell.add_key_command(py_cui.keys.KEY_B_UPPER,
+ self.song_seek_bck_long)
self.play_scroll_cell.add_key_command(py_cui.keys.KEY_TAB,
self._switch_to_nav)
self.play_scroll_cell.add_key_command(py_cui.keys.KEY_SPACE,
@@ -119,8 +127,7 @@ class SubClient:
self.play_scroll_cell.add_item_list(self.playlist)
def play_song(self):
- self.now_playing_block.set_title(
- self._now_playing_format('Now Playing', self.playlist[0]))
+ self._now_playing('Now Playing', self.playlist[0])
stream = self.subsonic.get_song_stream(self.playlist[0])
del self.playlist[0]
self.player.stop()
@@ -131,12 +138,27 @@ class SubClient:
state = 'Paused'
if paused:
state = 'Now Playing'
- self.now_playing_block.set_title(
- self._now_playing_format(state, self.current_song))
+ self._now_playing(state, self.current_song)
self.player.set_pause(not paused)
- def _now_playing_format(self, state, song):
- return (f'{state}:\n'
+ def song_seek_fwd_short(self):
+ self._song_seek('+5')
+
+ def song_seek_bck_short(self):
+ self._song_seek('-5')
+
+ def song_seek_fwd_long(self):
+ self._song_seek('+20')
+
+ def song_seek_bck_long(self):
+ self._song_seek('-20')
+
+ def _song_seek(self, duration='+5'):
+ self.player.seek(duration)
+
+ def _now_playing(self, state, song):
+ self.now_playing_block.set_title(
+ f'{state}:\n'
f'{song.title} ({helpers.format_duration(song.duration)})')
def _switch_to_nav(self):