From 803081f65a9a5b2fb9f733dd1c267a9557fb1a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Fri, 31 Jul 2020 23:45:54 +0200 Subject: [PATCH 1/5] Remove some generic exceptions --- jellyfin_kodi/connect.py | 2 +- jellyfin_kodi/downloader.py | 2 +- jellyfin_kodi/full_sync.py | 15 +++++++++------ jellyfin_kodi/helper/__init__.py | 1 - jellyfin_kodi/helper/exceptions.py | 12 ++++++++++++ jellyfin_kodi/jellyfin/exceptions.py | 11 ----------- jellyfin_kodi/jellyfin/http.py | 3 +-- jellyfin_kodi/library.py | 9 +++++---- jellyfin_kodi/objects/movies.py | 3 ++- jellyfin_kodi/objects/music.py | 4 +++- jellyfin_kodi/objects/musicvideos.py | 3 ++- jellyfin_kodi/objects/tvshows.py | 11 +++++++---- 12 files changed, 43 insertions(+), 33 deletions(-) delete mode 100644 jellyfin_kodi/jellyfin/exceptions.py diff --git a/jellyfin_kodi/connect.py b/jellyfin_kodi/connect.py index 7576b9de..c2d3c8ca 100644 --- a/jellyfin_kodi/connect.py +++ b/jellyfin_kodi/connect.py @@ -11,7 +11,7 @@ from dialogs import ServerConnect, UsersConnect, LoginManual, ServerManual from helper import settings, addon_id, event, api, window from jellyfin import Jellyfin from jellyfin.connection_manager import CONNECTION_STATE -from jellyfin.exceptions import HTTPException +from helper.exceptions import HTTPException from helper import LazyLogger ################################################################################################## diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index 3b0e0ab9..915b2bb7 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -14,7 +14,7 @@ import requests from helper import settings, stop, event, window, create_id from jellyfin import Jellyfin from jellyfin import api -from jellyfin.exceptions import HTTPException +from helper.exceptions import HTTPException from helper import LazyLogger ################################################################################################# diff --git a/jellyfin_kodi/full_sync.py b/jellyfin_kodi/full_sync.py index 66706661..09ba5b73 100644 --- a/jellyfin_kodi/full_sync.py +++ b/jellyfin_kodi/full_sync.py @@ -12,9 +12,10 @@ import downloader as server import helper.xmls as xmls from objects import Movies, TVShows, MusicVideos, Music from database import Database, get_sync, save_sync, jellyfin_db -from helper import translate, settings, window, progress, dialog, LibraryException +from helper import translate, settings, window, progress, dialog from helper.utils import get_screensaver, set_screensaver from helper import LazyLogger +from helper.exceptions import LibraryException, PathValidationException ################################################################################################## @@ -239,14 +240,16 @@ class FullSync(object): raise + except PathValidationException: + raise + except Exception as error: + dialog("ok", "{jellyfin}", translate(33119)) + + LOG.error("full sync exited unexpectedly") LOG.exception(error) - if 'Failed to validate path' not in error: - - dialog("ok", "{jellyfin}", translate(33119)) - LOG.error("full sync exited unexpectedly") - save_sync(self.sync) + save_sync(self.sync) raise diff --git a/jellyfin_kodi/helper/__init__.py b/jellyfin_kodi/helper/__init__.py index 8ba02c02..bae482a9 100644 --- a/jellyfin_kodi/helper/__init__.py +++ b/jellyfin_kodi/helper/__init__.py @@ -3,7 +3,6 @@ from __future__ import division, absolute_import, print_function, unicode_litera from .lazylogger import LazyLogger from .translate import translate -from .exceptions import LibraryException from .utils import addon_id from .utils import window diff --git a/jellyfin_kodi/helper/exceptions.py b/jellyfin_kodi/helper/exceptions.py index c7ca2291..ab2cd57c 100644 --- a/jellyfin_kodi/helper/exceptions.py +++ b/jellyfin_kodi/helper/exceptions.py @@ -4,7 +4,19 @@ from __future__ import division, absolute_import, print_function, unicode_litera ################################################################################################# +class HTTPException(Exception): + # Jellyfin HTTP exception + def __init__(self, status, message): + self.status = status + self.message = message + + class LibraryException(Exception): # Jellyfin library sync exception def __init__(self, status): self.status = status + + +class PathValidationException(Exception): + # raise Exception("Failed to validate path. User stopped.") + pass diff --git a/jellyfin_kodi/jellyfin/exceptions.py b/jellyfin_kodi/jellyfin/exceptions.py deleted file mode 100644 index 6cd50511..00000000 --- a/jellyfin_kodi/jellyfin/exceptions.py +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import division, absolute_import, print_function, unicode_literals - -################################################################################################# - - -class HTTPException(Exception): - # Jellyfin HTTP exception - def __init__(self, status, message): - self.status = status - self.message = message diff --git a/jellyfin_kodi/jellyfin/http.py b/jellyfin_kodi/jellyfin/http.py index 0bfe3ccd..ee3b10fa 100644 --- a/jellyfin_kodi/jellyfin/http.py +++ b/jellyfin_kodi/jellyfin/http.py @@ -10,8 +10,7 @@ from six import string_types, ensure_str from helper.utils import JsonDebugPrinter from helper import LazyLogger - -from .exceptions import HTTPException +from helper.exceptions import HTTPException ################################################################################################# diff --git a/jellyfin_kodi/library.py b/jellyfin_kodi/library.py index 20e5c2b8..603f0630 100644 --- a/jellyfin_kodi/library.py +++ b/jellyfin_kodi/library.py @@ -15,8 +15,9 @@ from database import Database, jellyfin_db, get_sync, save_sync from full_sync import FullSync from views import Views from downloader import GetItemWorker -from helper import translate, api, stop, settings, window, dialog, event, LibraryException +from helper import translate, api, stop, settings, window, dialog, event from helper.utils import split_list, set_screensaver, get_screensaver +from helper.exceptions import LibraryException from jellyfin import Jellyfin from helper import LazyLogger @@ -395,14 +396,14 @@ class Library(threading.Thread): try: # Get list of updates from server for synced library types and populate work queues result = self.server.jellyfin.get_sync_queue(last_sync, ",".join([ x for x in query_filter ])) - + if result is None: return True - + updated = [] userdata = [] removed = [] - + updated.extend(result['ItemsAdded']) updated.extend(result['ItemsUpdated']) userdata.extend(result['UserDataChanged']) diff --git a/jellyfin_kodi/objects/movies.py b/jellyfin_kodi/objects/movies.py index 27be5792..119e83d9 100644 --- a/jellyfin_kodi/objects/movies.py +++ b/jellyfin_kodi/objects/movies.py @@ -10,6 +10,7 @@ import downloader as server from database import jellyfin_db, queries as QUEM from helper import api, stop, validate, validate_bluray_dir, validate_dvd_dir, jellyfin_item, library_check, values, Local from helper import LazyLogger +from helper.exceptions import PathValidationException from .obj import Objects from .kodi import Movies as KodiDb, queries as QU @@ -173,7 +174,7 @@ class Movies(KodiDb): if self.direct_path: if not validate(obj['Path']): - raise Exception("Failed to validate path. User stopped.") + raise PathValidationException("Failed to validate path. User stopped.") obj['Path'] = obj['Path'].replace(obj['Filename'], "") diff --git a/jellyfin_kodi/objects/music.py b/jellyfin_kodi/objects/music.py index 755bc8ac..323eb498 100644 --- a/jellyfin_kodi/objects/music.py +++ b/jellyfin_kodi/objects/music.py @@ -8,9 +8,11 @@ import datetime from database import jellyfin_db, queries as QUEM from helper import api, stop, validate, jellyfin_item, values, library_check, Local from helper import LazyLogger +from helper.exceptions import PathValidationException from .obj import Objects from .kodi import Music as KodiDb, queries_music as QU + ################################################################################################## LOG = LazyLogger(__name__) @@ -325,7 +327,7 @@ class Music(KodiDb): if self.direct_path: if not validate(obj['Path']): - raise Exception("Failed to validate path. User stopped.") + raise PathValidationException("Failed to validate path. User stopped.") obj['Path'] = obj['Path'].replace(obj['Filename'], "") diff --git a/jellyfin_kodi/objects/musicvideos.py b/jellyfin_kodi/objects/musicvideos.py index d94ba3e7..c17c3935 100644 --- a/jellyfin_kodi/objects/musicvideos.py +++ b/jellyfin_kodi/objects/musicvideos.py @@ -12,6 +12,7 @@ from kodi_six.utils import py2_encode from database import jellyfin_db, queries as QUEM from helper import api, stop, validate, library_check, jellyfin_item, values, Local from helper import LazyLogger +from helper.exceptions import PathValidationException from .obj import Objects from .kodi import MusicVideos as KodiDb, queries as QU @@ -162,7 +163,7 @@ class MusicVideos(KodiDb): if self.direct_path: if not validate(obj['Path']): - raise Exception("Failed to validate path. User stopped.") + raise PathValidationException("Failed to validate path. User stopped.") obj['Path'] = obj['Path'].replace(obj['Filename'], "") diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index 01cd9abc..c4848cd1 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -13,6 +13,7 @@ import downloader as server from database import jellyfin_db, queries as QUEM from helper import api, stop, validate, jellyfin_item, library_check, values, Local from helper import LazyLogger +from helper.exceptions import PathValidationException from .obj import Objects from .kodi import TVShows as KodiDb, queries as QU @@ -195,7 +196,7 @@ class TVShows(KodiDb): obj['TopLevel'] = "plugin://plugin.video.jellyfin/" if not validate(obj['Path']): - raise Exception("Failed to validate path. User stopped.") + raise PathValidationException("Failed to validate path. User stopped.") else: obj['TopLevel'] = "plugin://plugin.video.jellyfin/%s/" % obj['LibraryId'] obj['Path'] = "%s%s/" % (obj['TopLevel'], obj['Id']) @@ -218,8 +219,9 @@ class TVShows(KodiDb): try: obj['ShowId'] = self.jellyfin_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj))[0] - except (KeyError, TypeError): + except (KeyError, TypeError) as error: LOG.error("Unable to add series %s", obj['SeriesId']) + LOG.exception(error) return False @@ -390,7 +392,7 @@ class TVShows(KodiDb): if self.direct_path: if not validate(obj['Path']): - raise Exception("Failed to validate path. User stopped.") + raise PathValidationException("Failed to validate path. User stopped.") obj['Path'] = obj['Path'].replace(obj['Filename'], "") else: @@ -411,8 +413,9 @@ class TVShows(KodiDb): try: self.tvshow(self.server.jellyfin.get_item(obj['SeriesId']), library=None) obj['ShowId'] = self.jellyfin_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj))[0] - except (TypeError, KeyError): + except (TypeError, KeyError) as error: LOG.error("Unable to add series %s", obj['SeriesId']) + LOG.exception(error) return False else: From 3ec71e89d661d1db10cae6691ee41e84953a788b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Fri, 31 Jul 2020 23:53:48 +0200 Subject: [PATCH 2/5] Refractor some decorators --- jellyfin_kodi/downloader.py | 2 +- jellyfin_kodi/helper/wrapper.py | 123 +++++++++++++-------------- jellyfin_kodi/library.py | 2 +- jellyfin_kodi/objects/movies.py | 18 ++-- jellyfin_kodi/objects/music.py | 26 +++--- jellyfin_kodi/objects/musicvideos.py | 14 +-- jellyfin_kodi/objects/tvshows.py | 22 ++--- 7 files changed, 101 insertions(+), 106 deletions(-) diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index 915b2bb7..ba701231 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -235,7 +235,7 @@ def get_songs_by_artist(artist_id, basic=False): yield items -@stop() +@stop def _get_items(query, server_id=None): ''' query = { diff --git a/jellyfin_kodi/helper/wrapper.py b/jellyfin_kodi/helper/wrapper.py index a0487a8a..d7c38004 100644 --- a/jellyfin_kodi/helper/wrapper.py +++ b/jellyfin_kodi/helper/wrapper.py @@ -38,6 +38,7 @@ def progress(message=None): if item: args = (item,) + args + LOG.debug({'self': self, 'dialog': dialog, 'args': args, 'kwargs': kwargs}) result = func(self, dialog=dialog, *args, **kwargs) dialog.close() @@ -81,99 +82,93 @@ def silent_catch(errors=(Exception,)): return decorator -def stop(default=None): +def stop(func): ''' Wrapper to catch exceptions and return using catch ''' - def decorator(func): - def wrapper(*args, **kwargs): + def wrapper(*args, **kwargs): - try: - if should_stop(): # ??? TODO: Fixme - raise Exception + try: + if should_stop(): # ??? TODO: Fixme + raise Exception - except Exception as error: - LOG.exception(error) + except Exception as error: + LOG.exception(error) - if default is not None: - return default + raise LibraryException("StopCalled") - raise LibraryException("StopCalled") + LOG.debug({'args': args, 'kwargs': kwargs}) + return func(*args, **kwargs) - return func(*args, **kwargs) - - return wrapper - return decorator + return wrapper -def jellyfin_item(): +def jellyfin_item(func): ''' Wrapper to retrieve the jellyfin_db item. ''' - def decorator(func): - def wrapper(self, item, *args, **kwargs): - e_item = self.jellyfin_db.get_item_by_id(item['Id'] if type(item) == dict else item) + def wrapper(self, item, *args, **kwargs): + e_item = self.jellyfin_db.get_item_by_id(item['Id'] if type(item) == dict else item) - return func(self, item, e_item=e_item, *args, **kwargs) + LOG.debug({'self': self, 'item': item, 'e_item': e_item, 'args': args, 'kwargs': kwargs}) + return func(self, item, e_item=e_item, *args, **kwargs) - return wrapper - return decorator + return wrapper -def library_check(): +def library_check(func): ''' Wrapper to retrieve the library ''' - def decorator(func): - def wrapper(self, item, *args, **kwargs): + def wrapper(self, item, *args, **kwargs): - ''' TODO: Rethink this one... songs and albums cannot be found by library. expensive. - ''' - from database import get_sync + ''' TODO: Rethink this one... songs and albums cannot be found by library. expensive. + ''' + from database import get_sync - if kwargs.get('library') is None: - sync = get_sync() + if kwargs.get('library') is None: + sync = get_sync() - if 'e_item' in kwargs: - try: - view_id = kwargs['e_item'][6] - view_name = self.jellyfin_db.get_view_name(view_id) - view = {'Name': view_name, 'Id': view_id} - except Exception: - view = None + if 'e_item' in kwargs: + try: + view_id = kwargs['e_item'][6] + view_name = self.jellyfin_db.get_view_name(view_id) + view = {'Name': view_name, 'Id': view_id} + except Exception: + view = None - if view is None: - ancestors = self.server.jellyfin.get_ancestors(item['Id']) + if view is None: + ancestors = self.server.jellyfin.get_ancestors(item['Id']) - if not ancestors: - if item['Type'] == 'MusicArtist': + if not ancestors: + if item['Type'] == 'MusicArtist': - try: - views = self.jellyfin_db.get_views_by_media('music')[0] - except Exception as error: - LOG.exception(error) - return - - view = {'Id': views[0], 'Name': views[1]} - else: # Grab the first music library + try: + views = self.jellyfin_db.get_views_by_media('music')[0] + except Exception as error: + LOG.exception(error) return - else: - for ancestor in ancestors: - if ancestor['Type'] == 'CollectionFolder': - - view = self.jellyfin_db.get_view_name(ancestor['Id']) - view = {'Id': None, 'Name': None} if view is None else {'Name': ancestor['Name'], 'Id': ancestor['Id']} - - break - - if view['Id'] not in [x.replace('Mixed:', "") for x in sync['Whitelist'] + sync['Libraries']]: - LOG.info("Library %s is not synced. Skip update.", view['Id']) + view = {'Id': views[0], 'Name': views[1]} + else: # Grab the first music library return + else: + for ancestor in ancestors: + if ancestor['Type'] == 'CollectionFolder': - kwargs['library'] = view + view = self.jellyfin_db.get_view_name(ancestor['Id']) + view = {'Id': None, 'Name': None} if view is None else {'Name': ancestor['Name'], 'Id': ancestor['Id']} - return func(self, item, *args, **kwargs) + break - return wrapper - return decorator + if view['Id'] not in [x.replace('Mixed:', "") for x in sync['Whitelist'] + sync['Libraries']]: + LOG.info("Library %s is not synced. Skip update.", view['Id']) + + return + + kwargs['library'] = view + + LOG.debug({'self': self, 'item': item, 'args': args, 'kwargs': kwargs}) + return func(self, item, *args, **kwargs) + + return wrapper diff --git a/jellyfin_kodi/library.py b/jellyfin_kodi/library.py index 603f0630..7a013abb 100644 --- a/jellyfin_kodi/library.py +++ b/jellyfin_kodi/library.py @@ -110,7 +110,7 @@ class Library(threading.Thread): with Database('video'), Database('music'): pass - @stop() + @stop def service(self): ''' If error is encountered, it will rerun this function. diff --git a/jellyfin_kodi/objects/movies.py b/jellyfin_kodi/objects/movies.py index 119e83d9..a1867d28 100644 --- a/jellyfin_kodi/objects/movies.py +++ b/jellyfin_kodi/objects/movies.py @@ -37,9 +37,9 @@ class Movies(KodiDb): KodiDb.__init__(self, videodb.cursor) - @stop() - @jellyfin_item() - @library_check() + @stop + @jellyfin_item + @library_check def movie(self, item, e_item, library): ''' If item does not exist, entry will be added. @@ -200,8 +200,8 @@ class Movies(KodiDb): } obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params)) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def boxset(self, item, e_item): ''' If item does not exist, entry will be added. @@ -281,8 +281,8 @@ class Movies(KodiDb): for boxset in boxsets: self.remove(boxset[0]) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def userdata(self, item, e_item): ''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks @@ -315,8 +315,8 @@ class Movies(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("USERDATA movie [%s/%s] %s: %s", obj['FileId'], obj['MovieId'], obj['Id'], obj['Title']) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def remove(self, item_id, e_item): ''' Remove movieid, fileid, jellyfin reference. diff --git a/jellyfin_kodi/objects/music.py b/jellyfin_kodi/objects/music.py index 323eb498..b139c4d7 100644 --- a/jellyfin_kodi/objects/music.py +++ b/jellyfin_kodi/objects/music.py @@ -35,9 +35,9 @@ class Music(KodiDb): KodiDb.__init__(self, musicdb.cursor) - @stop() - @jellyfin_item() - @library_check() + @stop + @jellyfin_item + @library_check def artist(self, item, e_item, library): ''' If item does not exist, entry will be added. @@ -103,8 +103,8 @@ class Music(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("UPDATE artist [%s] %s: %s", obj['ArtistId'], obj['Name'], obj['Id']) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def album(self, item, e_item): ''' Update object to kodi. @@ -209,9 +209,9 @@ class Music(KodiDb): self.link(*values(temp_obj, QU.update_link_obj)) self.item_ids.append(temp_obj['Id']) - @stop() - @jellyfin_item() - @library_check() + @stop + @jellyfin_item + @library_check def song(self, item, e_item, library): ''' Update object to kodi. @@ -402,8 +402,8 @@ class Music(KodiDb): obj['AlbumId'] = self.create_entry_album() self.add_single(*values(obj, QU.add_single_obj)) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def userdata(self, item, e_item): ''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks @@ -431,8 +431,8 @@ class Music(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("USERDATA %s [%s] %s: %s", obj['Media'], obj['KodiId'], obj['Id'], obj['Title']) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def remove(self, item_id, e_item): ''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks @@ -512,7 +512,7 @@ class Music(KodiDb): self.delete_song(kodi_id) LOG.debug("DELETE song [%s] %s", kodi_id, item_id) - @jellyfin_item() + @jellyfin_item def get_child(self, item_id, e_item): ''' Get all child elements from tv show jellyfin id. diff --git a/jellyfin_kodi/objects/musicvideos.py b/jellyfin_kodi/objects/musicvideos.py index c17c3935..d5e1fddf 100644 --- a/jellyfin_kodi/objects/musicvideos.py +++ b/jellyfin_kodi/objects/musicvideos.py @@ -39,9 +39,9 @@ class MusicVideos(KodiDb): KodiDb.__init__(self, videodb.cursor) - @stop() - @jellyfin_item() - @library_check() + @stop + @jellyfin_item + @library_check def musicvideo(self, item, e_item, library): ''' If item does not exist, entry will be added. @@ -177,8 +177,8 @@ class MusicVideos(KodiDb): } obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params)) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def userdata(self, item, e_item): ''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks @@ -210,8 +210,8 @@ class MusicVideos(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("USERDATA mvideo [%s/%s] %s: %s", obj['FileId'], obj['MvideoId'], obj['Id'], obj['Title']) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def remove(self, item_id, e_item): ''' Remove mvideoid, fileid, pathid, jellyfin reference. diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index c4848cd1..6247330c 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -41,9 +41,9 @@ class TVShows(KodiDb): KodiDb.__init__(self, videodb.cursor) - @stop() - @jellyfin_item() - @library_check() + @stop + @jellyfin_item + @library_check def tvshow(self, item, e_item, library): ''' If item does not exist, entry will be added. @@ -201,7 +201,7 @@ class TVShows(KodiDb): obj['TopLevel'] = "plugin://plugin.video.jellyfin/%s/" % obj['LibraryId'] obj['Path'] = "%s%s/" % (obj['TopLevel'], obj['Id']) - @stop() + @stop def season(self, item, show_id=None): ''' If item does not exist, entry will be added. @@ -235,8 +235,8 @@ class TVShows(KodiDb): self.artwork.add(obj['Artwork'], obj['SeasonId'], "season") LOG.debug("UPDATE season [%s/%s] %s: %s", obj['ShowId'], obj['SeasonId'], obj['Title'] or obj['Index'], obj['Id']) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def episode(self, item, e_item): ''' If item does not exist, entry will be added. @@ -425,8 +425,8 @@ class TVShows(KodiDb): return True - @stop() - @jellyfin_item() + @stop + @jellyfin_item def userdata(self, item, e_item): ''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks @@ -486,8 +486,8 @@ class TVShows(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("USERDATA %s [%s/%s] %s: %s", obj['Media'], obj['FileId'], obj['KodiId'], obj['Id'], obj['Title']) - @stop() - @jellyfin_item() + @stop + @jellyfin_item def remove(self, item_id, e_item): ''' Remove showid, fileid, pathid, jellyfin reference. @@ -589,7 +589,7 @@ class TVShows(KodiDb): self.delete_episode(kodi_id, file_id) LOG.debug("DELETE episode [%s/%s] %s", file_id, kodi_id, item_id) - @jellyfin_item() + @jellyfin_item def get_child(self, item_id, e_item): ''' Get all child elements from tv show jellyfin id. From 8b1c0bd1e49eed07a89f10a5c23bfeb1c6a82fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sat, 1 Aug 2020 00:03:40 +0200 Subject: [PATCH 3/5] Nuke catch and silent_catch decorators from orbit --- jellyfin_kodi/helper/__init__.py | 2 -- jellyfin_kodi/helper/wrapper.py | 34 -------------------------------- jellyfin_kodi/player.py | 14 ++++++++----- 3 files changed, 9 insertions(+), 41 deletions(-) diff --git a/jellyfin_kodi/helper/__init__.py b/jellyfin_kodi/helper/__init__.py index bae482a9..e4a65c98 100644 --- a/jellyfin_kodi/helper/__init__.py +++ b/jellyfin_kodi/helper/__init__.py @@ -25,8 +25,6 @@ from .utils import set_addon_mode from .utils import get_filesystem_encoding from .wrapper import progress -from .wrapper import catch -from .wrapper import silent_catch from .wrapper import stop from .wrapper import jellyfin_item from .wrapper import library_check diff --git a/jellyfin_kodi/helper/wrapper.py b/jellyfin_kodi/helper/wrapper.py index d7c38004..80693a12 100644 --- a/jellyfin_kodi/helper/wrapper.py +++ b/jellyfin_kodi/helper/wrapper.py @@ -48,40 +48,6 @@ def progress(message=None): return decorator -def catch(errors=(Exception,)): - - ''' Wrapper to catch exceptions and return using catch - ''' - def decorator(func): - def wrapper(*args, **kwargs): - - try: - return func(*args, **kwargs) - except errors as error: - LOG.exception(error) - - raise Exception("Caught exception") - - return wrapper - return decorator - - -def silent_catch(errors=(Exception,)): - - ''' Wrapper to catch exceptions and ignore them - ''' - def decorator(func): - def wrapper(*args, **kwargs): - - try: - return func(*args, **kwargs) - except errors as error: - LOG.error(error) - - return wrapper - return decorator - - def stop(func): ''' Wrapper to catch exceptions and return using catch diff --git a/jellyfin_kodi/player.py b/jellyfin_kodi/player.py index 8eefaf69..0772b57c 100644 --- a/jellyfin_kodi/player.py +++ b/jellyfin_kodi/player.py @@ -8,7 +8,7 @@ import os from kodi_six import xbmc, xbmcvfs from objects.obj import Objects -from helper import translate, api, window, settings, dialog, event, silent_catch, JSONRPC +from helper import translate, api, window, settings, dialog, event, JSONRPC from jellyfin import Jellyfin from helper import LazyLogger @@ -27,13 +27,17 @@ class Player(xbmc.Player): def __init__(self): xbmc.Player.__init__(self) - @silent_catch() def get_playing_file(self): - return self.getPlayingFile() + try: + return self.getPlayingFile() + except Exception as error: + LOG.exception(error) - @silent_catch() def get_file_info(self, file): - return self.played[file] + try: + return self.played[file] + except Exception as error: + LOG.exception(error) def is_playing_file(self, file): return file in self.played From f8c277a2c301ddbf83a7d2f78139093a33f07239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sun, 2 Aug 2020 14:59:46 +0200 Subject: [PATCH 4/5] Remove some excessively verbose debug logging --- jellyfin_kodi/helper/wrapper.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jellyfin_kodi/helper/wrapper.py b/jellyfin_kodi/helper/wrapper.py index 80693a12..de428163 100644 --- a/jellyfin_kodi/helper/wrapper.py +++ b/jellyfin_kodi/helper/wrapper.py @@ -38,7 +38,6 @@ def progress(message=None): if item: args = (item,) + args - LOG.debug({'self': self, 'dialog': dialog, 'args': args, 'kwargs': kwargs}) result = func(self, dialog=dialog, *args, **kwargs) dialog.close() @@ -63,7 +62,6 @@ def stop(func): raise LibraryException("StopCalled") - LOG.debug({'args': args, 'kwargs': kwargs}) return func(*args, **kwargs) return wrapper @@ -76,7 +74,6 @@ def jellyfin_item(func): def wrapper(self, item, *args, **kwargs): e_item = self.jellyfin_db.get_item_by_id(item['Id'] if type(item) == dict else item) - LOG.debug({'self': self, 'item': item, 'e_item': e_item, 'args': args, 'kwargs': kwargs}) return func(self, item, e_item=e_item, *args, **kwargs) return wrapper @@ -134,7 +131,6 @@ def library_check(func): kwargs['library'] = view - LOG.debug({'self': self, 'item': item, 'args': args, 'kwargs': kwargs}) return func(self, item, *args, **kwargs) return wrapper From 50e514459c05158b89f0c7484fc90547dea7d59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sun, 2 Aug 2020 15:07:11 +0200 Subject: [PATCH 5/5] Replace commented code with docstring --- jellyfin_kodi/helper/exceptions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jellyfin_kodi/helper/exceptions.py b/jellyfin_kodi/helper/exceptions.py index ab2cd57c..2a53b008 100644 --- a/jellyfin_kodi/helper/exceptions.py +++ b/jellyfin_kodi/helper/exceptions.py @@ -18,5 +18,9 @@ class LibraryException(Exception): class PathValidationException(Exception): - # raise Exception("Failed to validate path. User stopped.") + """ + Replacing generic `Exception` + + TODO: Investigate the usage of this to see if it can be done better. + """ pass