From 1a62661473e41e40a9165db085ff28c8719727fd Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Tue, 19 Jul 2022 21:07:02 -0400 Subject: Info mode bug fixes and more Fixed a couple of bugs with info mode. Info mode now displays properly and without a focus highlight. Using 'h' or 'l' in info mode no longer crashes the program. Added type hinting where I had not already. --- config.py | 2 +- database.py | 4 ++-- interface.py | 20 ++++++++++---------- jellyfin.py | 25 +++++++++++-------------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/config.py b/config.py index 184dbd8..845d6e4 100644 --- a/config.py +++ b/config.py @@ -14,7 +14,7 @@ def read_config_file(): return parser -def write_config_file(parser): +def write_config_file(parser:ConfigParser): """ Write ConfigParser contents back to config file """ with open(os.path.expanduser(CONFIG_FILE), "w") as conf: parser.write(conf) diff --git a/database.py b/database.py index 1c5304c..039a893 100644 --- a/database.py +++ b/database.py @@ -27,7 +27,7 @@ class Database(object): )""") - def query_playstate(self, item_id): + def query_playstate(self, item_id:str): """ Gets the playstate data for a given item id """ with sqlite3.connect(self.path) as conn: c = conn.cursor() @@ -39,7 +39,7 @@ class Database(object): return playstate - def update_playstate(self, item_id, pct_played, sec_played): + def update_playstate(self, item_id:str, pct_played:float, sec_played:int): """ Updates the playstate of a given item id """ with sqlite3.connect(self.path) as conn: c = conn.cursor() diff --git a/interface.py b/interface.py index 5d3ff24..817e7b1 100644 --- a/interface.py +++ b/interface.py @@ -130,7 +130,7 @@ class Interface: def build(self): """ Build urwid/curses UI """ - self.header = urwid.AttrWrap(urwid.Text("joc"), "header") + self.header = urwid.AttrWrap(urwid.Text("Main Mode"), "header") self.content = urwid.SimpleFocusListWalker([]) self.body = urwid.ListBox(self.content) self.display_contents = self.libs @@ -163,11 +163,11 @@ class Interface: sys.exit(0) - def keypress(self, key): + def keypress(self, key:str): """ Handle a key press by the user """ if self.ui_main.get_focus() == "body": if key == 'h' or key == 'left': - if not self.search_mode: + if not self.search_mode and not self.info_mode: self.shift_left() self.clear_buffer() elif key == 'enter': @@ -188,7 +188,7 @@ class Interface: self.content.set_focus(self.focus) self.clear_buffer() elif key == 'l'or key == 'right': - if not self.search_mode: + if not self.search_mode and not self.info_mode: self.shift_right() self.clear_buffer() elif key == 'i': @@ -422,9 +422,9 @@ class Interface: self.display_contents = content if self.info_mode: + content = content[0].split("\n") for line in content: - self.content.append(urwid.AttrWrap( - urwid.Text(line), 'text','focus')) + self.content.append(urwid.AttrWrap(urwid.Text(line), 'text')) self.content.set_focus(0) return @@ -468,7 +468,7 @@ class Interface: self.content.set_focus(self.focus) - def is_media(self, item): + def is_media(self, item:dict): """ Determines if an item is a piece of media (as opposed to a container) and returns a boolean. Determination is made by 'Type' field in Jellyfin item JSON. """ @@ -593,7 +593,7 @@ class Interface: - def get_playstate(self, item_id): + def get_playstate(self, item_id:str): DB_ITEMID_INDEX = 0 DB_PCT_INDEX = 1 DB_SEC_INDEX = 2 @@ -602,7 +602,7 @@ class Interface: playstate = self.db.query_playstate(item_id) return playstate[DB_PCT_INDEX],playstate[DB_SEC_INDEX] - def set_playstate(self, item_id, pct_played, sec_played): + def set_playstate(self, item_id:str, pct_played:str, sec_played:str): """ Updates playstate in local db of an item """ pct_played = float(pct_played) sec_played = int(sec_played) @@ -623,4 +623,4 @@ class Interface: focus_item = self.display_contents[self.focus] info = self.jellyfin.get_info(focus_item["Id"]) - self.display(info) + self.display([info]) diff --git a/jellyfin.py b/jellyfin.py index 007dccf..05c020a 100644 --- a/jellyfin.py +++ b/jellyfin.py @@ -13,6 +13,7 @@ import threading import subprocess import ssl import shlex +from configparser import ConfigParser APP_NAME = "joc" CLIENT_VERSION = "0.01" @@ -38,7 +39,7 @@ def die(msg): class JellyfinConnection(object): - def __init__(self, parser): + def __init__(self, parser:ConfigParser): self.parser = parser @@ -96,7 +97,7 @@ class JellyfinConnection(object): warnings.filterwarnings("ignore") return client - def login(self, server, username, password): + def login(self, server:str, username:str, password:str): """ Login to Jellyfin server with JellyfinClient instance """ client = self.client_factory() @@ -126,7 +127,7 @@ class JellyfinConnection(object): folders = self.api.get_media_folders()["Items"] return sorted(folders,key=lambda folder: folder["Name"]) - def get_children(self,parent_id): + def get_children(self,parent_id:str): """ Get children of a given parent_id. Sorts by date created if items are videos or by name otherwise. Returns the sotrted list """ @@ -143,7 +144,7 @@ class JellyfinConnection(object): return children - def get_previous(self,item_id): + def get_previous(self,item_id:str): """Gets items that were shown on the previous screen, i.e. the parent item's siblings, i.e. the children of the grandparent item """ @@ -158,7 +159,7 @@ class JellyfinConnection(object): return self.get_children(grandparent["Id"]) - def get_parent(self,item_id): + def get_parent(self,item_id:str): """ Get parent (first ancestor) of a given item """ PARENT_INDEX = 0 @@ -166,7 +167,7 @@ class JellyfinConnection(object): parent = ancestors[PARENT_INDEX] return parent - def search(self, term): + def search(self, term:str): """ Search for a given term and return a alphabetically sorted list """ items = self.api.search_media_items(term,MEDIA_TYPES,None)["Items"] @@ -178,25 +179,21 @@ class JellyfinConnection(object): string representation of the item """ item = self.api.get_item(item_id) - return json.dumps(item,indent=4) + return json.dumps(item,indent=2) - def mark_watched(self, item_id, watched=True): + def mark_watched(self, item_id:str, watched=True): """ Mark an item as watched or unwatched""" self.api.item_played(item_id, watched) - def mark_favorite(self, item_id, favorite=True): + def mark_favorite(self, item_id:str, favorite=True): """ Mark an item as a favorite or unfavorite the item""" self.api.favorite(item_id, favorite) - def get_url(self, item_id): + def get_url(self, item_id:str): """ Get download URL of the selected media item """ url = self.api.download_url(item_id) return url - def set_played_progress(self, item:dict, ticks): - item["UserData"]["PlaybackPositionTicks"] = int(ticks) - res = self.api.session_progress(item) - if __name__ == '__main__': main() -- cgit v1.2.3