subclient

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

commit e65e114f024ac64ac28f78f55917e4f29bf5a0a4
parent f1ead763fba163407c16d3ee0e2a2a8cd8081fc4
Author: Paco Esteban <paco@e1e0.net>
Date:   Thu, 10 Jun 2021 15:38:25 +0200

mocking now playing message

Diffstat:
Dhelpers.py | 13-------------
Asubclient/helpers.py | 14++++++++++++++
Msubclient/subclient.py | 23+++++++++++++++++------
3 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/helpers.py b/helpers.py @@ -1,13 +0,0 @@ -import time - - -def format_duration(seconds): - """Formats a number of seconds in hours:minutes:seconds - - :param seconds: The number of seconds to format - :type seconds: int - :return: String of the form "%H:%M:%S" - :rtype: string - """ - ty_res = time.gmtime(seconds) - return time.strftime("%H:%M:%S", ty_res) diff --git a/subclient/helpers.py b/subclient/helpers.py @@ -0,0 +1,14 @@ +import time + + +def format_duration(seconds): + """Formats a number of seconds in hours:minutes:seconds + + :param seconds: The number of seconds to format + :type seconds: int + :return: String of the form "%H:%M:%S" + :rtype: string + """ + time_format = "%H:%M:%S" if seconds > 3600 else "%M:%S" + ty_res = time.gmtime(seconds) + return time.strftime(time_format, ty_res) diff --git a/subclient/subclient.py b/subclient/subclient.py @@ -2,6 +2,7 @@ import configparser from subclient.subsonic import Subsonic +from subclient import helpers import py_cui @@ -19,18 +20,20 @@ class SubClient: # The scrolled list cells that will contain our tasks in each of the # three categories self.artist_scroll_cell = self.master.add_scroll_menu( - 'Artists', 0, 0, row_span=1, column_span=1) + 'Artists', 0, 0, row_span=4, column_span=1) self.album_scroll_cell = self.master.add_scroll_menu( - 'Albums', 0, 1, row_span=1, column_span=1) + 'Albums', 0, 1, row_span=4, column_span=1) self.song_scroll_cell = self.master.add_scroll_menu( - 'Songs', 0, 2, row_span=1, column_span=1) + 'Songs', 0, 2, row_span=4, column_span=1) + self.now_playing_block = self.master.add_block_label( + 'Now', 4, 0, row_span=1, column_span=3) self.artist_scroll_cell.add_key_command(py_cui.keys.KEY_ENTER, self.update_albums) self.album_scroll_cell.add_key_command(py_cui.keys.KEY_ENTER, self.update_songs) - # self.song_scroll_cell.add_key_command(py_cui.keys.KEY_ENTER, - # self.play_song) + self.song_scroll_cell.add_key_command(py_cui.keys.KEY_ENTER, + self.play_song) self.update_artists() @@ -50,9 +53,17 @@ class SubClient: songs = self.subsonic.get_songs_from_album(album) self.song_scroll_cell.add_item_list(songs) + def play_song(self): + song = self.song_scroll_cell.get() + self.now_playing_block.set_title(self._now_playing_format(song)) + + def _now_playing_format(self, song): + return (f'Now playing:\n' + f'{song.title} ({helpers.format_duration(song.duration)})') + def main(): - root = py_cui.PyCUI(1, 3) + root = py_cui.PyCUI(5, 3) # enable unicode box chars root.toggle_unicode_borders() root.set_title('SubsonicClient')