mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-05-02 15:38:47 +00:00
Merge pull request #345 from oddstr13/pr-cleanup-1
A tiny bit of code cleanup
This commit is contained in:
commit
da21f49928
14 changed files with 155 additions and 182 deletions
|
@ -11,7 +11,7 @@ from dialogs import ServerConnect, UsersConnect, LoginManual, ServerManual
|
||||||
from helper import settings, addon_id, event, api, window
|
from helper import settings, addon_id, event, api, window
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
from jellyfin.connection_manager import CONNECTION_STATE
|
from jellyfin.connection_manager import CONNECTION_STATE
|
||||||
from jellyfin.exceptions import HTTPException
|
from helper.exceptions import HTTPException
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
|
@ -14,7 +14,7 @@ import requests
|
||||||
from helper import settings, stop, event, window, create_id
|
from helper import settings, stop, event, window, create_id
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
from jellyfin import api
|
from jellyfin import api
|
||||||
from jellyfin.exceptions import HTTPException
|
from helper.exceptions import HTTPException
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
@ -235,7 +235,7 @@ def get_songs_by_artist(artist_id, basic=False):
|
||||||
yield items
|
yield items
|
||||||
|
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
def _get_items(query, server_id=None):
|
def _get_items(query, server_id=None):
|
||||||
|
|
||||||
''' query = {
|
''' query = {
|
||||||
|
|
|
@ -12,9 +12,10 @@ import downloader as server
|
||||||
import helper.xmls as xmls
|
import helper.xmls as xmls
|
||||||
from objects import Movies, TVShows, MusicVideos, Music
|
from objects import Movies, TVShows, MusicVideos, Music
|
||||||
from database import Database, get_sync, save_sync, jellyfin_db
|
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.utils import get_screensaver, set_screensaver
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.exceptions import LibraryException, PathValidationException
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
|
@ -239,14 +240,16 @@ class FullSync(object):
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
except PathValidationException:
|
||||||
|
raise
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
dialog("ok", "{jellyfin}", translate(33119))
|
||||||
|
|
||||||
|
LOG.error("full sync exited unexpectedly")
|
||||||
LOG.exception(error)
|
LOG.exception(error)
|
||||||
|
|
||||||
if 'Failed to validate path' not in error:
|
save_sync(self.sync)
|
||||||
|
|
||||||
dialog("ok", "{jellyfin}", translate(33119))
|
|
||||||
LOG.error("full sync exited unexpectedly")
|
|
||||||
save_sync(self.sync)
|
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
||||||
from .lazylogger import LazyLogger
|
from .lazylogger import LazyLogger
|
||||||
|
|
||||||
from .translate import translate
|
from .translate import translate
|
||||||
from .exceptions import LibraryException
|
|
||||||
|
|
||||||
from .utils import addon_id
|
from .utils import addon_id
|
||||||
from .utils import window
|
from .utils import window
|
||||||
|
@ -26,8 +25,6 @@ from .utils import set_addon_mode
|
||||||
from .utils import get_filesystem_encoding
|
from .utils import get_filesystem_encoding
|
||||||
|
|
||||||
from .wrapper import progress
|
from .wrapper import progress
|
||||||
from .wrapper import catch
|
|
||||||
from .wrapper import silent_catch
|
|
||||||
from .wrapper import stop
|
from .wrapper import stop
|
||||||
from .wrapper import jellyfin_item
|
from .wrapper import jellyfin_item
|
||||||
from .wrapper import library_check
|
from .wrapper import library_check
|
||||||
|
|
|
@ -4,7 +4,23 @@ 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):
|
class LibraryException(Exception):
|
||||||
# Jellyfin library sync exception
|
# Jellyfin library sync exception
|
||||||
def __init__(self, status):
|
def __init__(self, status):
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
|
|
||||||
|
class PathValidationException(Exception):
|
||||||
|
"""
|
||||||
|
Replacing generic `Exception`
|
||||||
|
|
||||||
|
TODO: Investigate the usage of this to see if it can be done better.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
|
@ -47,133 +47,90 @@ def progress(message=None):
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def catch(errors=(Exception,)):
|
def stop(func):
|
||||||
|
|
||||||
''' Wrapper to catch exceptions and return using catch
|
''' Wrapper to catch exceptions and return using catch
|
||||||
'''
|
'''
|
||||||
def decorator(func):
|
def wrapper(*args, **kwargs):
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwargs)
|
if should_stop(): # ??? TODO: Fixme
|
||||||
except errors as error:
|
raise Exception
|
||||||
LOG.exception(error)
|
|
||||||
|
|
||||||
raise Exception("Caught exception")
|
except Exception as error:
|
||||||
|
LOG.exception(error)
|
||||||
|
|
||||||
return wrapper
|
raise LibraryException("StopCalled")
|
||||||
return decorator
|
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def silent_catch(errors=(Exception,)):
|
def jellyfin_item(func):
|
||||||
|
|
||||||
''' 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(default=None):
|
|
||||||
|
|
||||||
''' Wrapper to catch exceptions and return using catch
|
|
||||||
'''
|
|
||||||
def decorator(func):
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
|
|
||||||
try:
|
|
||||||
if should_stop(): # ??? TODO: Fixme
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
except Exception as error:
|
|
||||||
LOG.exception(error)
|
|
||||||
|
|
||||||
if default is not None:
|
|
||||||
return default
|
|
||||||
|
|
||||||
raise LibraryException("StopCalled")
|
|
||||||
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
def jellyfin_item():
|
|
||||||
|
|
||||||
''' Wrapper to retrieve the jellyfin_db item.
|
''' Wrapper to retrieve the jellyfin_db item.
|
||||||
'''
|
'''
|
||||||
def decorator(func):
|
def wrapper(self, item, *args, **kwargs):
|
||||||
def wrapper(self, item, *args, **kwargs):
|
e_item = self.jellyfin_db.get_item_by_id(item['Id'] if type(item) == dict else item)
|
||||||
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)
|
return func(self, item, e_item=e_item, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
def library_check():
|
def library_check(func):
|
||||||
|
|
||||||
''' Wrapper to retrieve the library
|
''' 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.
|
''' TODO: Rethink this one... songs and albums cannot be found by library. expensive.
|
||||||
'''
|
'''
|
||||||
from database import get_sync
|
from database import get_sync
|
||||||
|
|
||||||
if kwargs.get('library') is None:
|
if kwargs.get('library') is None:
|
||||||
sync = get_sync()
|
sync = get_sync()
|
||||||
|
|
||||||
if 'e_item' in kwargs:
|
if 'e_item' in kwargs:
|
||||||
try:
|
try:
|
||||||
view_id = kwargs['e_item'][6]
|
view_id = kwargs['e_item'][6]
|
||||||
view_name = self.jellyfin_db.get_view_name(view_id)
|
view_name = self.jellyfin_db.get_view_name(view_id)
|
||||||
view = {'Name': view_name, 'Id': view_id}
|
view = {'Name': view_name, 'Id': view_id}
|
||||||
except Exception:
|
except Exception:
|
||||||
view = None
|
view = None
|
||||||
|
|
||||||
if view is None:
|
if view is None:
|
||||||
ancestors = self.server.jellyfin.get_ancestors(item['Id'])
|
ancestors = self.server.jellyfin.get_ancestors(item['Id'])
|
||||||
|
|
||||||
if not ancestors:
|
if not ancestors:
|
||||||
if item['Type'] == 'MusicArtist':
|
if item['Type'] == 'MusicArtist':
|
||||||
|
|
||||||
try:
|
try:
|
||||||
views = self.jellyfin_db.get_views_by_media('music')[0]
|
views = self.jellyfin_db.get_views_by_media('music')[0]
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
LOG.exception(error)
|
LOG.exception(error)
|
||||||
return
|
|
||||||
|
|
||||||
view = {'Id': views[0], 'Name': views[1]}
|
|
||||||
else: # Grab the first music library
|
|
||||||
return
|
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
|
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
|
if view['Id'] not in [x.replace('Mixed:', "") for x in sync['Whitelist'] + sync['Libraries']]:
|
||||||
return decorator
|
LOG.info("Library %s is not synced. Skip update.", view['Id'])
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
kwargs['library'] = view
|
||||||
|
|
||||||
|
return func(self, item, *args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
|
@ -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
|
|
|
@ -10,8 +10,7 @@ from six import string_types, ensure_str
|
||||||
|
|
||||||
from helper.utils import JsonDebugPrinter
|
from helper.utils import JsonDebugPrinter
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.exceptions import HTTPException
|
||||||
from .exceptions import HTTPException
|
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,9 @@ from database import Database, jellyfin_db, get_sync, save_sync
|
||||||
from full_sync import FullSync
|
from full_sync import FullSync
|
||||||
from views import Views
|
from views import Views
|
||||||
from downloader import GetItemWorker
|
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.utils import split_list, set_screensaver, get_screensaver
|
||||||
|
from helper.exceptions import LibraryException
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ class Library(threading.Thread):
|
||||||
with Database('video'), Database('music'):
|
with Database('video'), Database('music'):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
def service(self):
|
def service(self):
|
||||||
|
|
||||||
''' If error is encountered, it will rerun this function.
|
''' If error is encountered, it will rerun this function.
|
||||||
|
@ -395,14 +396,14 @@ class Library(threading.Thread):
|
||||||
try:
|
try:
|
||||||
# Get list of updates from server for synced library types and populate work queues
|
# 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 ]))
|
result = self.server.jellyfin.get_sync_queue(last_sync, ",".join([ x for x in query_filter ]))
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
updated = []
|
updated = []
|
||||||
userdata = []
|
userdata = []
|
||||||
removed = []
|
removed = []
|
||||||
|
|
||||||
updated.extend(result['ItemsAdded'])
|
updated.extend(result['ItemsAdded'])
|
||||||
updated.extend(result['ItemsUpdated'])
|
updated.extend(result['ItemsUpdated'])
|
||||||
userdata.extend(result['UserDataChanged'])
|
userdata.extend(result['UserDataChanged'])
|
||||||
|
|
|
@ -10,6 +10,7 @@ import downloader as server
|
||||||
from database import jellyfin_db, queries as QUEM
|
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 api, stop, validate, validate_bluray_dir, validate_dvd_dir, jellyfin_item, library_check, values, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
from .kodi import Movies as KodiDb, queries as QU
|
from .kodi import Movies as KodiDb, queries as QU
|
||||||
|
@ -36,9 +37,9 @@ class Movies(KodiDb):
|
||||||
|
|
||||||
KodiDb.__init__(self, videodb.cursor)
|
KodiDb.__init__(self, videodb.cursor)
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
@library_check()
|
@library_check
|
||||||
def movie(self, item, e_item, library):
|
def movie(self, item, e_item, library):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -173,7 +174,7 @@ class Movies(KodiDb):
|
||||||
if self.direct_path:
|
if self.direct_path:
|
||||||
|
|
||||||
if not validate(obj['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'], "")
|
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
|
||||||
|
|
||||||
|
@ -199,8 +200,8 @@ class Movies(KodiDb):
|
||||||
}
|
}
|
||||||
obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params))
|
obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params))
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def boxset(self, item, e_item):
|
def boxset(self, item, e_item):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -280,8 +281,8 @@ class Movies(KodiDb):
|
||||||
for boxset in boxsets:
|
for boxset in boxsets:
|
||||||
self.remove(boxset[0])
|
self.remove(boxset[0])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def userdata(self, item, e_item):
|
def userdata(self, item, e_item):
|
||||||
|
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
|
@ -314,8 +315,8 @@ class Movies(KodiDb):
|
||||||
self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj))
|
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'])
|
LOG.debug("USERDATA movie [%s/%s] %s: %s", obj['FileId'], obj['MovieId'], obj['Id'], obj['Title'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def remove(self, item_id, e_item):
|
def remove(self, item_id, e_item):
|
||||||
|
|
||||||
''' Remove movieid, fileid, jellyfin reference.
|
''' Remove movieid, fileid, jellyfin reference.
|
||||||
|
|
|
@ -8,9 +8,11 @@ import datetime
|
||||||
from database import jellyfin_db, queries as QUEM
|
from database import jellyfin_db, queries as QUEM
|
||||||
from helper import api, stop, validate, jellyfin_item, values, library_check, Local
|
from helper import api, stop, validate, jellyfin_item, values, library_check, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
from .kodi import Music as KodiDb, queries_music as QU
|
from .kodi import Music as KodiDb, queries_music as QU
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
LOG = LazyLogger(__name__)
|
LOG = LazyLogger(__name__)
|
||||||
|
@ -33,9 +35,9 @@ class Music(KodiDb):
|
||||||
|
|
||||||
KodiDb.__init__(self, musicdb.cursor)
|
KodiDb.__init__(self, musicdb.cursor)
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
@library_check()
|
@library_check
|
||||||
def artist(self, item, e_item, library):
|
def artist(self, item, e_item, library):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -101,8 +103,8 @@ class Music(KodiDb):
|
||||||
self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj))
|
self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj))
|
||||||
LOG.debug("UPDATE artist [%s] %s: %s", obj['ArtistId'], obj['Name'], obj['Id'])
|
LOG.debug("UPDATE artist [%s] %s: %s", obj['ArtistId'], obj['Name'], obj['Id'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def album(self, item, e_item):
|
def album(self, item, e_item):
|
||||||
|
|
||||||
''' Update object to kodi.
|
''' Update object to kodi.
|
||||||
|
@ -207,9 +209,9 @@ class Music(KodiDb):
|
||||||
self.link(*values(temp_obj, QU.update_link_obj))
|
self.link(*values(temp_obj, QU.update_link_obj))
|
||||||
self.item_ids.append(temp_obj['Id'])
|
self.item_ids.append(temp_obj['Id'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
@library_check()
|
@library_check
|
||||||
def song(self, item, e_item, library):
|
def song(self, item, e_item, library):
|
||||||
|
|
||||||
''' Update object to kodi.
|
''' Update object to kodi.
|
||||||
|
@ -325,7 +327,7 @@ class Music(KodiDb):
|
||||||
if self.direct_path:
|
if self.direct_path:
|
||||||
|
|
||||||
if not validate(obj['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'], "")
|
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
|
||||||
|
|
||||||
|
@ -400,8 +402,8 @@ class Music(KodiDb):
|
||||||
obj['AlbumId'] = self.create_entry_album()
|
obj['AlbumId'] = self.create_entry_album()
|
||||||
self.add_single(*values(obj, QU.add_single_obj))
|
self.add_single(*values(obj, QU.add_single_obj))
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def userdata(self, item, e_item):
|
def userdata(self, item, e_item):
|
||||||
|
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
|
@ -429,8 +431,8 @@ class Music(KodiDb):
|
||||||
self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj))
|
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'])
|
LOG.debug("USERDATA %s [%s] %s: %s", obj['Media'], obj['KodiId'], obj['Id'], obj['Title'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def remove(self, item_id, e_item):
|
def remove(self, item_id, e_item):
|
||||||
|
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
|
@ -510,7 +512,7 @@ class Music(KodiDb):
|
||||||
self.delete_song(kodi_id)
|
self.delete_song(kodi_id)
|
||||||
LOG.debug("DELETE song [%s] %s", kodi_id, item_id)
|
LOG.debug("DELETE song [%s] %s", kodi_id, item_id)
|
||||||
|
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def get_child(self, item_id, e_item):
|
def get_child(self, item_id, e_item):
|
||||||
|
|
||||||
''' Get all child elements from tv show jellyfin id.
|
''' Get all child elements from tv show jellyfin id.
|
||||||
|
|
|
@ -12,6 +12,7 @@ from kodi_six.utils import py2_encode
|
||||||
from database import jellyfin_db, queries as QUEM
|
from database import jellyfin_db, queries as QUEM
|
||||||
from helper import api, stop, validate, library_check, jellyfin_item, values, Local
|
from helper import api, stop, validate, library_check, jellyfin_item, values, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
from .kodi import MusicVideos as KodiDb, queries as QU
|
from .kodi import MusicVideos as KodiDb, queries as QU
|
||||||
|
@ -38,9 +39,9 @@ class MusicVideos(KodiDb):
|
||||||
|
|
||||||
KodiDb.__init__(self, videodb.cursor)
|
KodiDb.__init__(self, videodb.cursor)
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
@library_check()
|
@library_check
|
||||||
def musicvideo(self, item, e_item, library):
|
def musicvideo(self, item, e_item, library):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -162,7 +163,7 @@ class MusicVideos(KodiDb):
|
||||||
if self.direct_path:
|
if self.direct_path:
|
||||||
|
|
||||||
if not validate(obj['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'], "")
|
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
|
||||||
|
|
||||||
|
@ -176,8 +177,8 @@ class MusicVideos(KodiDb):
|
||||||
}
|
}
|
||||||
obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params))
|
obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params))
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def userdata(self, item, e_item):
|
def userdata(self, item, e_item):
|
||||||
|
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
|
@ -209,8 +210,8 @@ class MusicVideos(KodiDb):
|
||||||
self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj))
|
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'])
|
LOG.debug("USERDATA mvideo [%s/%s] %s: %s", obj['FileId'], obj['MvideoId'], obj['Id'], obj['Title'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def remove(self, item_id, e_item):
|
def remove(self, item_id, e_item):
|
||||||
|
|
||||||
''' Remove mvideoid, fileid, pathid, jellyfin reference.
|
''' Remove mvideoid, fileid, pathid, jellyfin reference.
|
||||||
|
|
|
@ -13,6 +13,7 @@ import downloader as server
|
||||||
from database import jellyfin_db, queries as QUEM
|
from database import jellyfin_db, queries as QUEM
|
||||||
from helper import api, stop, validate, jellyfin_item, library_check, values, Local
|
from helper import api, stop, validate, jellyfin_item, library_check, values, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
from .kodi import TVShows as KodiDb, queries as QU
|
from .kodi import TVShows as KodiDb, queries as QU
|
||||||
|
@ -40,9 +41,9 @@ class TVShows(KodiDb):
|
||||||
|
|
||||||
KodiDb.__init__(self, videodb.cursor)
|
KodiDb.__init__(self, videodb.cursor)
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
@library_check()
|
@library_check
|
||||||
def tvshow(self, item, e_item, library):
|
def tvshow(self, item, e_item, library):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -195,12 +196,12 @@ class TVShows(KodiDb):
|
||||||
obj['TopLevel'] = "plugin://plugin.video.jellyfin/"
|
obj['TopLevel'] = "plugin://plugin.video.jellyfin/"
|
||||||
|
|
||||||
if not validate(obj['Path']):
|
if not validate(obj['Path']):
|
||||||
raise Exception("Failed to validate path. User stopped.")
|
raise PathValidationException("Failed to validate path. User stopped.")
|
||||||
else:
|
else:
|
||||||
obj['TopLevel'] = "plugin://plugin.video.jellyfin/%s/" % obj['LibraryId']
|
obj['TopLevel'] = "plugin://plugin.video.jellyfin/%s/" % obj['LibraryId']
|
||||||
obj['Path'] = "%s%s/" % (obj['TopLevel'], obj['Id'])
|
obj['Path'] = "%s%s/" % (obj['TopLevel'], obj['Id'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
def season(self, item, show_id=None):
|
def season(self, item, show_id=None):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -218,8 +219,9 @@ class TVShows(KodiDb):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj['ShowId'] = self.jellyfin_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj))[0]
|
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.error("Unable to add series %s", obj['SeriesId'])
|
||||||
|
LOG.exception(error)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -233,8 +235,8 @@ class TVShows(KodiDb):
|
||||||
self.artwork.add(obj['Artwork'], obj['SeasonId'], "season")
|
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'])
|
LOG.debug("UPDATE season [%s/%s] %s: %s", obj['ShowId'], obj['SeasonId'], obj['Title'] or obj['Index'], obj['Id'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def episode(self, item, e_item):
|
def episode(self, item, e_item):
|
||||||
|
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
|
@ -390,7 +392,7 @@ class TVShows(KodiDb):
|
||||||
if self.direct_path:
|
if self.direct_path:
|
||||||
|
|
||||||
if not validate(obj['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'], "")
|
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
|
||||||
else:
|
else:
|
||||||
|
@ -411,8 +413,9 @@ class TVShows(KodiDb):
|
||||||
try:
|
try:
|
||||||
self.tvshow(self.server.jellyfin.get_item(obj['SeriesId']), library=None)
|
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]
|
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.error("Unable to add series %s", obj['SeriesId'])
|
||||||
|
LOG.exception(error)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -422,8 +425,8 @@ class TVShows(KodiDb):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def userdata(self, item, e_item):
|
def userdata(self, item, e_item):
|
||||||
|
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
|
@ -483,8 +486,8 @@ class TVShows(KodiDb):
|
||||||
self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj))
|
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'])
|
LOG.debug("USERDATA %s [%s/%s] %s: %s", obj['Media'], obj['FileId'], obj['KodiId'], obj['Id'], obj['Title'])
|
||||||
|
|
||||||
@stop()
|
@stop
|
||||||
@jellyfin_item()
|
@jellyfin_item
|
||||||
def remove(self, item_id, e_item):
|
def remove(self, item_id, e_item):
|
||||||
|
|
||||||
''' Remove showid, fileid, pathid, jellyfin reference.
|
''' Remove showid, fileid, pathid, jellyfin reference.
|
||||||
|
@ -586,7 +589,7 @@ class TVShows(KodiDb):
|
||||||
self.delete_episode(kodi_id, file_id)
|
self.delete_episode(kodi_id, file_id)
|
||||||
LOG.debug("DELETE episode [%s/%s] %s", file_id, kodi_id, item_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):
|
def get_child(self, item_id, e_item):
|
||||||
|
|
||||||
''' Get all child elements from tv show jellyfin id.
|
''' Get all child elements from tv show jellyfin id.
|
||||||
|
|
|
@ -8,7 +8,7 @@ import os
|
||||||
from kodi_six import xbmc, xbmcvfs
|
from kodi_six import xbmc, xbmcvfs
|
||||||
|
|
||||||
from objects.obj import Objects
|
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 jellyfin import Jellyfin
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
|
||||||
|
@ -27,13 +27,17 @@ class Player(xbmc.Player):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
xbmc.Player.__init__(self)
|
xbmc.Player.__init__(self)
|
||||||
|
|
||||||
@silent_catch()
|
|
||||||
def get_playing_file(self):
|
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):
|
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):
|
def is_playing_file(self, file):
|
||||||
return file in self.played
|
return file in self.played
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue