Merge pull request #349 from mcarlton00/why-is-everything-awful

Metadata syncing rework
This commit is contained in:
Abby 2020-08-03 20:20:22 +01:00 committed by GitHub
commit 128e636070
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 186 additions and 202 deletions

View file

@ -189,31 +189,40 @@ def get_items(parent_id, item_type=None, basic=False, params=None):
yield items yield items
def get_artists(parent_id=None, basic=False, params=None, server_id=None): def get_artists(parent_id=None):
query = { url = "Artists"
'url': "Artists",
'params': { params = {
'UserId': "{UserId}", 'UserId': "{UserId}",
'ParentId': parent_id, 'ParentId': parent_id,
'SortBy': "SortName", 'SortBy': "SortName",
'SortOrder': "Ascending", 'SortOrder': "Ascending",
'Fields': api.basic_info() if basic else api.music_info(), 'Fields': api.music_info(),
'CollapseBoxSetItems': False, 'CollapseBoxSetItems': False,
'IsVirtualUnaired': False, 'IsVirtualUnaired': False,
'EnableTotalRecordCount': False, 'EnableTotalRecordCount': False,
'LocationTypes': "FileSystem,Remote,Offline", 'LocationTypes': "FileSystem,Remote,Offline",
'IsMissing': False, 'IsMissing': False,
'Recursive': True 'Recursive': True
}
} }
if params: return _get(url, params)
query['params'].update(params)
for items in _get_items(query, server_id):
yield items
def get_library_items(library_id, item_type):
url = "Users/{UserId}/Items"
params = {
'ParentId': library_id,
'IncludeItemTypes': item_type,
'SortBy': "SortName",
'SortOrder': "Ascending",
'Fields': api.info(),
'Recursive': True,
}
return _get(url, params)
def get_albums_by_artist(artist_id, basic=False): def get_albums_by_artist(artist_id, basic=False):

View file

@ -213,11 +213,19 @@ class FullSync(object):
} }
try: try:
if library_id.startswith('Boxsets:'): if library_id.startswith('Boxsets:'):
boxset_library = {}
if library_id.endswith('Refresh'): libraries = self.get_libraries(library_id.split('Boxsets:')[1] if len(library_id) > len('Boxsets:') else None)
self.refresh_boxsets() for entry in libraries:
else: if entry[2] == 'boxsets':
self.boxsets(library_id.split('Boxsets:')[1] if len(library_id) > len('Boxsets:') else None) boxset_library = {'Id': entry[0], 'Name': entry[1]}
break
if boxset_library:
if library_id.endswith('Refresh'):
self.refresh_boxsets(boxset_library)
else:
self.boxsets(boxset_library)
return return
@ -270,7 +278,7 @@ class FullSync(object):
for items in server.get_items(library['Id'], "Movie", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "Movie", False, self.sync['RestorePoint'].get('params')):
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path) obj = Movies(self.server, jellyfindb, videodb, self.direct_path, library)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
@ -280,11 +288,11 @@ class FullSync(object):
dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100), dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100),
heading="%s: %s" % (translate('addon_name'), library['Name']), heading="%s: %s" % (translate('addon_name'), library['Name']),
message=movie['Name']) message=movie['Name'])
obj.movie(movie, library=library) obj.movie(movie)
processed_ids.append(movie['Id']) processed_ids.append(movie['Id'])
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path) obj = Movies(self.server, jellyfindb, videodb, self.direct_path, library)
obj.item_ids = processed_ids obj.item_ids = processed_ids
if self.update_library: if self.update_library:
@ -313,7 +321,7 @@ class FullSync(object):
for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')):
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True) obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, library, True)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
@ -324,7 +332,7 @@ class FullSync(object):
message = show['Name'] message = show['Name']
dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message) dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message)
if obj.tvshow(show, library=library) is not False: if obj.tvshow(show) is not False:
for episodes in server.get_episode_by_show(show['Id']): for episodes in server.get_episode_by_show(show['Id']):
for episode in episodes['Items']: for episode in episodes['Items']:
@ -334,7 +342,7 @@ class FullSync(object):
processed_ids.append(show['Id']) processed_ids.append(show['Id'])
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True) obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, library, True)
obj.item_ids = processed_ids obj.item_ids = processed_ids
if self.update_library: if self.update_library:
self.tvshows_compare(library, obj, jellyfindb) self.tvshows_compare(library, obj, jellyfindb)
@ -365,7 +373,7 @@ class FullSync(object):
for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')):
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path) obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path, library)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
@ -375,11 +383,11 @@ class FullSync(object):
dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100), dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100),
heading="%s: %s" % (translate('addon_name'), library['Name']), heading="%s: %s" % (translate('addon_name'), library['Name']),
message=mvideo['Name']) message=mvideo['Name'])
obj.musicvideo(mvideo, library=library) obj.musicvideo(mvideo)
processed_ids.append(mvideo['Id']) processed_ids.append(mvideo['Id'])
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path) obj = MusicVideos(self.server, jellyfindb, videodb, self.direct_path, library)
obj.item_ids = processed_ids obj.item_ids = processed_ids
if self.update_library: if self.update_library:
self.musicvideos_compare(library, obj, jellyfindb) self.musicvideos_compare(library, obj, jellyfindb)
@ -405,38 +413,41 @@ class FullSync(object):
with self.library.music_database_lock: with self.library.music_database_lock:
with Database('music') as musicdb: with Database('music') as musicdb:
with Database('jellyfin') as jellyfindb: with Database('jellyfin') as jellyfindb:
obj = Music(self.server, jellyfindb, musicdb, self.direct_path) obj = Music(self.server, jellyfindb, musicdb, self.direct_path, library)
for items in server.get_artists(library['Id'], False, self.sync['RestorePoint'].get('params')): library_id = library['Id']
self.sync['RestorePoint'] = items['RestorePoint'] # Get all items in the library to process locally
start_index = items['RestorePoint']['params']['StartIndex'] artists_data = server.get_artists(library_id)
artists = artists_data['Items']
num_artists = artists_data['TotalRecordCount']
albums = server.get_library_items(library_id, 'MusicAlbum')['Items']
songs = server.get_library_items(library_id, 'Audio')['Items']
for index, artist in enumerate(items['Items']): for index, artist in enumerate(artists):
artist_name = artist.get('Name')
percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100) # Update percentage dialog
message = artist['Name'] percent = int((float(index) / float(num_artists)) * 100)
dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message) dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=artist_name)
obj.artist(artist, library=library)
for albums in server.get_albums_by_artist(artist['Id']): # Add artist to database
obj.artist(artist)
for album in albums['Items']:
obj.album(album)
for songs in server.get_items(album['Id'], "Audio"):
for song in songs['Items']:
dialog.update(percent,
message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
obj.song(song)
for songs in server.get_songs_by_artist(artist['Id']):
for song in songs['Items']:
dialog.update(percent, message="%s/%s" % (message, song['Name']))
obj.song(song)
# Get all albums for each artist
artist_albums = [ album for album in albums if artist_name in album.get('Artists') ]
for album in artist_albums:
# Add album to database
obj.album(album)
album_id = album.get('Id')
# Get all songs in each album
album_songs = [ song for song in songs if album_id == song.get('AlbumId') ]
for song in album_songs:
dialog.update(percent,
message="%s/%s/%s" % (artist_name, album['Name'][:7], song['Name'][:7]))
# Add song to database
obj.song(song)
#
if self.update_library: if self.update_library:
self.music_compare(library, obj, jellyfindb) self.music_compare(library, obj, jellyfindb)
@ -457,14 +468,14 @@ class FullSync(object):
obj.remove(x[0]) obj.remove(x[0])
@progress(translate(33018)) @progress(translate(33018))
def boxsets(self, library_id=None, dialog=None): def boxsets(self, library, dialog=None):
''' Process all boxsets. ''' Process all boxsets.
''' '''
for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "BoxSet", False, self.sync['RestorePoint'].get('params')):
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path) obj = Movies(self.server, jellyfindb, videodb, self.direct_path, library)
self.sync['RestorePoint'] = items['RestorePoint'] self.sync['RestorePoint'] = items['RestorePoint']
start_index = items['RestorePoint']['params']['StartIndex'] start_index = items['RestorePoint']['params']['StartIndex']
@ -476,12 +487,12 @@ class FullSync(object):
message=boxset['Name']) message=boxset['Name'])
obj.boxset(boxset) obj.boxset(boxset)
def refresh_boxsets(self): def refresh_boxsets(self, library):
''' Delete all exisitng boxsets and re-add. ''' Delete all exisitng boxsets and re-add.
''' '''
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path) obj = Movies(self.server, jellyfindb, videodb, self.direct_path, library)
obj.boxsets_reset() obj.boxsets_reset()
self.boxsets(None) self.boxsets(None)
@ -514,7 +525,7 @@ class FullSync(object):
movies = [x for x in items if x[1] == 'Movie'] movies = [x for x in items if x[1] == 'Movie']
tvshows = [x for x in items if x[1] == 'Series'] tvshows = [x for x in items if x[1] == 'Series']
obj = Movies(self.server, jellyfindb, kodidb, direct_path).remove obj = Movies(self.server, jellyfindb, kodidb, direct_path, library).remove
for item in movies: for item in movies:
@ -522,7 +533,7 @@ class FullSync(object):
dialog.update(int((float(count) / float(len(items)) * 100)), heading="%s: %s" % (translate('addon_name'), library[0])) dialog.update(int((float(count) / float(len(items)) * 100)), heading="%s: %s" % (translate('addon_name'), library[0]))
count += 1 count += 1
obj = TVShows(self.server, jellyfindb, kodidb, direct_path).remove obj = TVShows(self.server, jellyfindb, kodidb, direct_path, library).remove
for item in tvshows: for item in tvshows:

View file

@ -27,4 +27,3 @@ from .utils import get_filesystem_encoding
from .wrapper import progress from .wrapper import progress
from .wrapper import stop from .wrapper import stop
from .wrapper import jellyfin_item from .wrapper import jellyfin_item
from .wrapper import library_check

View file

@ -21,6 +21,7 @@ from kodi_six import xbmc, xbmcaddon, xbmcgui, xbmcvfs
from . import LazyLogger from . import LazyLogger
from .translate import translate from .translate import translate
################################################################################################# #################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)
@ -535,3 +536,18 @@ def get_filesystem_encoding():
enc = 'utf-8' enc = 'utf-8'
return enc return enc
def find_library(server, item):
from database import get_sync
sync = get_sync()
ancestors = server.jellyfin.get_ancestors(item['Id'])
for ancestor in ancestors:
if ancestor['Id'] in sync['Whitelist']:
LOG.info('Ancestor Found')
return ancestor
LOG.error('No ancestor found, not syncing item with ID: {}'.format(item['Id']))
return {}

View file

@ -77,60 +77,3 @@ def jellyfin_item(func):
return func(self, item, e_item=e_item, *args, **kwargs) return func(self, item, e_item=e_item, *args, **kwargs)
return wrapper return wrapper
def library_check(func):
''' Wrapper to retrieve the library
'''
def wrapper(self, item, *args, **kwargs):
''' 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 '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 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
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'])
return
kwargs['library'] = view
return func(self, item, *args, **kwargs)
return wrapper

View file

@ -16,7 +16,7 @@ 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 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, find_library
from helper.exceptions import LibraryException from helper.exceptions import LibraryException
from jellyfin import Jellyfin from jellyfin import Jellyfin
from helper import LazyLogger from helper import LazyLogger
@ -605,36 +605,39 @@ class UpdateWorker(threading.Thread):
except Queue.Empty: except Queue.Empty:
break break
default_args = (self.server, jellyfindb, kodidb, self.direct_path) # Verify that the updated item is in our local whitelist
if item['Type'] == 'Movie': library = find_library(self.server, item)
obj = Movies(*default_args).movie if library:
elif item['Type'] == 'BoxSet': default_args = (self.server, jellyfindb, kodidb, self.direct_path, library)
obj = Movies(*default_args).boxset try:
elif item['Type'] == 'Series': if item['Type'] == 'Movie':
obj = TVShows(*default_args).tvshow Movies(*default_args).movie(item)
elif item['Type'] == 'Season': elif item['Type'] == 'BoxSet':
obj = TVShows(*default_args).season Movies(*default_args).boxset(item)
elif item['Type'] == 'Episode': elif item['Type'] == 'Series':
obj = TVShows(*default_args).episode TVShows(*default_args).tvshow(item)
elif item['Type'] == 'MusicVideo': elif item['Type'] == 'Season':
obj = MusicVideos(*default_args).musicvideo TVShows(*default_args).season(item)
elif item['Type'] == 'MusicAlbum': elif item['Type'] == 'Episode':
obj = Music(*default_args).album TVShows(*default_args).episode(item)
elif item['Type'] == 'MusicArtist': elif item['Type'] == 'MusicVideo':
obj = Music(*default_args).artist MusicVideos(*default_args).musicvideo(item)
elif item['Type'] == 'AlbumArtist': elif item['Type'] == 'MusicAlbum':
obj = Music(*default_args).albumartist Music(*default_args).album(item)
elif item['Type'] == 'Audio': elif item['Type'] == 'MusicArtist':
obj = Music(*default_args).song Music(*default_args).artist(item)
elif item['Type'] == 'AlbumArtist':
Music(*default_args).albumartist(item)
elif item['Type'] == 'Audio':
Music(*default_args).song(item)
try: if self.notify:
if obj(item) and self.notify: self.notify_output.put((item['Type'], api.API(item).get_naming()))
self.notify_output.put((item['Type'], api.API(item).get_naming())) except LibraryException as error:
except LibraryException as error: if error.status == 'StopCalled':
if error.status == 'StopCalled': break
break except Exception as error:
except Exception as error: LOG.exception(error)
LOG.exception(error)
self.queue.task_done() self.queue.task_done()
@ -667,24 +670,28 @@ class UserDataWorker(threading.Thread):
except Queue.Empty: except Queue.Empty:
break break
try: # Verify that the updated item is in our local whitelist
if item['Type'] == 'Movie': library = find_library(self.server, item)
Movies(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item) if library:
elif item['Type'] in ['Series', 'Season', 'Episode']: default_args = (self.server, jellyfindb, kodidb, self.direct_path, library)
TVShows(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item) try:
elif item['Type'] == 'MusicAlbum': if item['Type'] == 'Movie':
Music(self.args[0], jellyfindb, kodidb, self.args[1]).album(item) Movies(*default_args).userdata(item)
elif item['Type'] == 'MusicArtist': elif item['Type'] in ['Series', 'Season', 'Episode']:
Music(self.args[0], jellyfindb, kodidb, self.args[1]).artist(item) TVShows(*default_args).userdata(item)
elif item['Type'] == 'AlbumArtist': elif item['Type'] == 'MusicAlbum':
Music(self.args[0], jellyfindb, kodidb, self.args[1]).albumartist(item) Music(*default_args).album(item)
elif item['Type'] == 'Audio': elif item['Type'] == 'MusicArtist':
Music(self.args[0], jellyfindb, kodidb, self.args[1]).song(item) Music(*default_args).artist(item)
except LibraryException as error: elif item['Type'] == 'AlbumArtist':
if error.status == 'StopCalled': Music(*default_args).albumartist(item)
break elif item['Type'] == 'Audio':
except Exception as error: Music(*default_args).song(item)
LOG.exception(error) except LibraryException as error:
if error.status == 'StopCalled':
break
except Exception as error:
LOG.exception(error)
self.queue.task_done() self.queue.task_done()

View file

@ -8,7 +8,7 @@ from kodi_six.utils import py2_encode
import downloader as server 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, values, Local
from helper import LazyLogger from helper import LazyLogger
from helper.exceptions import PathValidationException from helper.exceptions import PathValidationException
@ -24,7 +24,7 @@ LOG = LazyLogger(__name__)
class Movies(KodiDb): class Movies(KodiDb):
def __init__(self, server, jellyfindb, videodb, direct_path): def __init__(self, server, jellyfindb, videodb, direct_path, library=None):
self.server = server self.server = server
self.jellyfin = jellyfindb self.jellyfin = jellyfindb
@ -34,13 +34,13 @@ class Movies(KodiDb):
self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor) self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = [] self.item_ids = []
self.library = library
KodiDb.__init__(self, videodb.cursor) KodiDb.__init__(self, videodb.cursor)
@stop @stop
@jellyfin_item @jellyfin_item
@library_check def movie(self, item, e_item):
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.
If item exists, entry will be updated. If item exists, entry will be updated.
@ -65,8 +65,8 @@ class Movies(KodiDb):
LOG.info("MovieId %s missing from kodi. repairing the entry.", obj['MovieId']) LOG.info("MovieId %s missing from kodi. repairing the entry.", obj['MovieId'])
obj['Path'] = API.get_file_path(obj['Path']) obj['Path'] = API.get_file_path(obj['Path'])
obj['LibraryId'] = library['Id'] obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = library['Name'] obj['LibraryName'] = self.library['Name']
obj['Genres'] = obj['Genres'] or [] obj['Genres'] = obj['Genres'] or []
obj['Studios'] = [API.validate_studio(studio) for studio in (obj['Studios'] or [])] obj['Studios'] = [API.validate_studio(studio) for studio in (obj['Studios'] or [])]
obj['People'] = obj['People'] or [] obj['People'] = obj['People'] or []

View file

@ -6,7 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import datetime 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, Local
from helper import LazyLogger from helper import LazyLogger
from helper.exceptions import PathValidationException from helper.exceptions import PathValidationException
@ -22,7 +22,7 @@ LOG = LazyLogger(__name__)
class Music(KodiDb): class Music(KodiDb):
def __init__(self, server, jellyfindb, musicdb, direct_path): def __init__(self, server, jellyfindb, musicdb, direct_path, library=None):
self.server = server self.server = server
self.jellyfin = jellyfindb self.jellyfin = jellyfindb
@ -32,13 +32,13 @@ class Music(KodiDb):
self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor) self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = [] self.item_ids = []
self.library = library
KodiDb.__init__(self, musicdb.cursor) KodiDb.__init__(self, musicdb.cursor)
@stop @stop
@jellyfin_item @jellyfin_item
@library_check def artist(self, item, e_item):
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.
If item exists, entry will be updated. If item exists, entry will be updated.
@ -60,8 +60,8 @@ class Music(KodiDb):
update = False update = False
LOG.info("ArtistId %s missing from kodi. repairing the entry.", obj['ArtistId']) LOG.info("ArtistId %s missing from kodi. repairing the entry.", obj['ArtistId'])
obj['LibraryId'] = library['Id'] obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = library['Name'] obj['LibraryName'] = self.library['Name']
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['ArtistType'] = "MusicArtist" obj['ArtistType'] = "MusicArtist"
obj['Genre'] = " / ".join(obj['Genres'] or []) obj['Genre'] = " / ".join(obj['Genres'] or [])
@ -199,7 +199,7 @@ class Music(KodiDb):
except TypeError: except TypeError:
try: try:
self.artist(self.server.jellyfin.get_item(temp_obj['Id']), library=None) self.artist(self.server.jellyfin.get_item(temp_obj['Id']))
temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception(error)
@ -211,8 +211,7 @@ class Music(KodiDb):
@stop @stop
@jellyfin_item @jellyfin_item
@library_check def song(self, item, e_item):
def song(self, item, e_item, library):
''' Update object to kodi. ''' Update object to kodi.
''' '''
@ -354,7 +353,7 @@ class Music(KodiDb):
except TypeError: except TypeError:
try: try:
self.artist(self.server.jellyfin.get_item(temp_obj['Id']), library=None) self.artist(self.server.jellyfin.get_item(temp_obj['Id']))
temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception(error)
@ -388,7 +387,7 @@ class Music(KodiDb):
except TypeError: except TypeError:
try: try:
self.artist(self.server.jellyfin.get_item(temp_obj['Id']), library=None) self.artist(self.server.jellyfin.get_item(temp_obj['Id']))
temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception(error)

View file

@ -10,7 +10,7 @@ from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode 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, jellyfin_item, values, Local
from helper import LazyLogger from helper import LazyLogger
from helper.exceptions import PathValidationException from helper.exceptions import PathValidationException
@ -26,7 +26,7 @@ LOG = LazyLogger(__name__)
class MusicVideos(KodiDb): class MusicVideos(KodiDb):
def __init__(self, server, jellyfindb, videodb, direct_path): def __init__(self, server, jellyfindb, videodb, direct_path, library=None):
self.server = server self.server = server
self.jellyfin = jellyfindb self.jellyfin = jellyfindb
@ -36,13 +36,13 @@ class MusicVideos(KodiDb):
self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor) self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = [] self.item_ids = []
self.library = library
KodiDb.__init__(self, videodb.cursor) KodiDb.__init__(self, videodb.cursor)
@stop @stop
@jellyfin_item @jellyfin_item
@library_check def musicvideo(self, item, e_item):
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.
If item exists, entry will be updated. If item exists, entry will be updated.
@ -70,8 +70,8 @@ class MusicVideos(KodiDb):
LOG.info("MvideoId %s missing from kodi. repairing the entry.", obj['MvideoId']) LOG.info("MvideoId %s missing from kodi. repairing the entry.", obj['MvideoId'])
obj['Path'] = API.get_file_path(obj['Path']) obj['Path'] = API.get_file_path(obj['Path'])
obj['LibraryId'] = library['Id'] obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = library['Name'] obj['LibraryName'] = self.library['Name']
obj['Genres'] = obj['Genres'] or [] obj['Genres'] = obj['Genres'] or []
obj['ArtistItems'] = obj['ArtistItems'] or [] obj['ArtistItems'] = obj['ArtistItems'] or []
obj['Studios'] = [API.validate_studio(studio) for studio in (obj['Studios'] or [])] obj['Studios'] = [API.validate_studio(studio) for studio in (obj['Studios'] or [])]

View file

@ -11,7 +11,7 @@ from kodi_six.utils import py2_encode
import downloader as server 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, values, Local
from helper import LazyLogger from helper import LazyLogger
from helper.exceptions import PathValidationException from helper.exceptions import PathValidationException
@ -27,7 +27,7 @@ LOG = LazyLogger(__name__)
class TVShows(KodiDb): class TVShows(KodiDb):
def __init__(self, server, jellyfindb, videodb, direct_path, update_library=False): def __init__(self, server, jellyfindb, videodb, direct_path, library=None, update_library=False):
self.server = server self.server = server
self.jellyfin = jellyfindb self.jellyfin = jellyfindb
@ -38,13 +38,13 @@ class TVShows(KodiDb):
self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor) self.jellyfin_db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
self.objects = Objects() self.objects = Objects()
self.item_ids = [] self.item_ids = []
self.library = library
KodiDb.__init__(self, videodb.cursor) KodiDb.__init__(self, videodb.cursor)
@stop @stop
@jellyfin_item @jellyfin_item
@library_check def tvshow(self, item, e_item):
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.
If item exists, entry will be updated. If item exists, entry will be updated.
@ -72,8 +72,8 @@ class TVShows(KodiDb):
LOG.info("ShowId %s missing from kodi. repairing the entry.", obj['ShowId']) LOG.info("ShowId %s missing from kodi. repairing the entry.", obj['ShowId'])
obj['Path'] = API.get_file_path(obj['Path']) obj['Path'] = API.get_file_path(obj['Path'])
obj['LibraryId'] = library['Id'] obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = library['Name'] obj['LibraryName'] = self.library['Name']
obj['Genres'] = obj['Genres'] or [] obj['Genres'] = obj['Genres'] or []
obj['People'] = obj['People'] or [] obj['People'] = obj['People'] or []
obj['Mpaa'] = API.get_mpaa(obj['Mpaa']) obj['Mpaa'] = API.get_mpaa(obj['Mpaa'])
@ -411,7 +411,7 @@ class TVShows(KodiDb):
if obj['ShowId'] is None: if obj['ShowId'] is None:
try: try:
self.tvshow(self.server.jellyfin.get_item(obj['SeriesId']), library=None) self.tvshow(self.server.jellyfin.get_item(obj['SeriesId']))
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) as error: except (TypeError, KeyError) as error:
LOG.error("Unable to add series %s", obj['SeriesId']) LOG.error("Unable to add series %s", obj['SeriesId'])