commit a9e43ad70ec93b7820b80e4f4c2be828471aee22
parent 0221b01a01de62e2600e965320fb3554d5ea3e8d
Author: Paco Esteban <paco@e1e0.net>
Date: Sun, 27 Jun 2021 18:31:10 +0200
implement albums, artitsts and songs navigation
Diffstat:
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/subclient/subclient.py b/subclient/subclient.py
@@ -22,6 +22,12 @@ def get_config_file():
class SubClient:
UP = -1
DOWN = 1
+ OUT = -1
+ IN = 1
+
+ ARTISTS = 0
+ ALBUMS = 1
+ SONGS = 2
def __init__(self):
self.config = configparser.ConfigParser()
@@ -35,12 +41,15 @@ class SubClient:
self.init_curses()
self.nav_list = self.subsonic.get_artists()
+ self.nav_list_type = self.ARTISTS
self.nav_selected = 0
self.nav_top = 0
self.nav_bottom = len(self.nav_list)
self.nav_max_lines = curses.LINES
self.nav_pages = self.nav_bottom // self.nav_max_lines
+ self.artist = None
+
def init_curses(self):
self.window = curses.initscr()
self.window.keypad(True)
@@ -77,6 +86,10 @@ class SubClient:
self.nav_page(self.DOWN)
elif c == 'b':
self.nav_page(self.UP)
+ elif c == 'l':
+ self.nav_in_out(self.IN)
+ elif c == 'h':
+ self.nav_in_out(self.OUT)
elif c in [curses.KEY_ENTER, '\r', '\n']:
with open('foo.txt', 'w') as f:
print(f"top: {self.nav_top}", file=f)
@@ -88,9 +101,9 @@ class SubClient:
for i, t in enumerate(
self.nav_list[self.nav_top:self.nav_top + self.nav_max_lines]):
if i == self.nav_selected:
- self.window.addstr(i, 0, t.name, curses.A_REVERSE)
+ self.window.addstr(i, 0, str(t), curses.A_REVERSE)
else:
- self.window.addstr(i, 0, t.name)
+ self.window.addstr(i, 0, str(t))
def nav_scroll(self, direction):
# next cursor position
@@ -125,7 +138,7 @@ class SubClient:
# Without overflow
# next cursor position is above max lines, so we increment the
# selected line
- if next_line < self.nav_max_lines:
+ if next_line < self.nav_max_lines and next_line < self.nav_bottom:
self.nav_selected = next_line
return
@@ -151,6 +164,29 @@ class SubClient:
self.nav_top = self.nav_bottom - self.nav_max_lines
return
+ def nav_in_out(self, direction):
+ self.nav_list_type += direction
+
+ # we keep track of the artist, which is the only thing we need really
+ # if is None we get it from the current list, and we reset it to None
+ # when we go back to the artists list
+ if self.nav_list_type == self.ARTISTS:
+ self.nav_list = self.subsonic.get_artists()
+ if self.artist is not None:
+ self.artist = None
+ elif self.nav_list_type == self.ALBUMS:
+ if self.artist is None:
+ self.artist = self.nav_list[self.nav_top + self.nav_selected]
+ self.nav_list = self.subsonic.get_albums_from_artist(self.artist)
+ elif self.nav_list_type == self.SONGS:
+ album = self.nav_list[self.nav_top + self.nav_selected]
+ self.nav_list = self.subsonic.get_songs_from_album(album)
+
+ self.nav_top = 0
+ self.nav_selected = 0
+ self.nav_bottom = len(self.nav_list)
+ self.nav_pages = self.nav_bottom // self.nav_max_lines
+
def refresh(self):
self.window.noutrefresh()
curses.doupdate()