mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Merge pull request #362 from mcarlton00/might've-used-too-much
Refactor metadata ancestor gathering
This commit is contained in:
commit
8b1b648dfa
7 changed files with 124 additions and 69 deletions
|
@ -105,13 +105,9 @@ class JellyfinDatabase():
|
||||||
|
|
||||||
def get_view_name(self, item_id):
|
def get_view_name(self, item_id):
|
||||||
|
|
||||||
try:
|
|
||||||
self.cursor.execute(QU.get_view_name, (item_id,))
|
self.cursor.execute(QU.get_view_name, (item_id,))
|
||||||
|
|
||||||
return self.cursor.fetchone()[0]
|
return self.cursor.fetchone()[0]
|
||||||
except Exception as error:
|
|
||||||
LOG.exception(error)
|
|
||||||
return
|
|
||||||
|
|
||||||
def get_view(self, *args):
|
def get_view(self, *args):
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,8 @@ add_reference_pool_obj = ["{SeriesId}", "{ShowId}", None, "{PathId}", "Series",
|
||||||
add_reference_episode_obj = ["{Id}", "{EpisodeId}", "{FileId}", "{PathId}", "Episode", "episode", "{SeasonId}", "{Checksum}", None, "{JellyfinParentId}"]
|
add_reference_episode_obj = ["{Id}", "{EpisodeId}", "{FileId}", "{PathId}", "Episode", "episode", "{SeasonId}", "{Checksum}", None, "{JellyfinParentId}"]
|
||||||
add_reference_mvideo_obj = ["{Id}", "{MvideoId}", "{FileId}", "{PathId}", "MusicVideo", "musicvideo", None, "{Checksum}", "{LibraryId}", "{JellyfinParentId}"]
|
add_reference_mvideo_obj = ["{Id}", "{MvideoId}", "{FileId}", "{PathId}", "MusicVideo", "musicvideo", None, "{Checksum}", "{LibraryId}", "{JellyfinParentId}"]
|
||||||
add_reference_artist_obj = ["{Id}", "{ArtistId}", None, None, "{ArtistType}", "artist", None, "{Checksum}", "{LibraryId}", "{JellyfinParentId}"]
|
add_reference_artist_obj = ["{Id}", "{ArtistId}", None, None, "{ArtistType}", "artist", None, "{Checksum}", "{LibraryId}", "{JellyfinParentId}"]
|
||||||
add_reference_album_obj = ["{Id}", "{AlbumId}", None, None, "MusicAlbum", "album", None, "{Checksum}", None, "{JellyfinParentId}"]
|
add_reference_album_obj = ["{Id}", "{AlbumId}", None, None, "MusicAlbum", "album", None, "{Checksum}", "{LibraryId}", "{JellyfinParentId}"]
|
||||||
add_reference_song_obj = ["{Id}", "{SongId}", None, "{PathId}", "Audio", "song", "{AlbumId}", "{Checksum}", None, "{JellyfinParentId}"]
|
add_reference_song_obj = ["{Id}", "{SongId}", None, "{PathId}", "Audio", "song", "{AlbumId}", "{Checksum}", "{LibraryId}", "{JellyfinParentId}"]
|
||||||
add_view = """
|
add_view = """
|
||||||
INSERT OR REPLACE INTO view(view_id, view_name, media_type)
|
INSERT OR REPLACE INTO view(view_id, view_name, media_type)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
|
|
|
@ -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, find_library
|
from helper.utils import split_list, set_screensaver, get_screensaver
|
||||||
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,11 +605,9 @@ class UpdateWorker(threading.Thread):
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Verify that the updated item is in our local whitelist
|
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
||||||
library = find_library(self.server, item)
|
|
||||||
if library:
|
|
||||||
default_args = (self.server, jellyfindb, kodidb, self.direct_path, library)
|
|
||||||
try:
|
try:
|
||||||
|
LOG.debug('{} - {}'.format(item['Type'], item['Name']))
|
||||||
if item['Type'] == 'Movie':
|
if item['Type'] == 'Movie':
|
||||||
Movies(*default_args).movie(item)
|
Movies(*default_args).movie(item)
|
||||||
elif item['Type'] == 'BoxSet':
|
elif item['Type'] == 'BoxSet':
|
||||||
|
@ -672,10 +670,7 @@ class UserDataWorker(threading.Thread):
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Verify that the updated item is in our local whitelist
|
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
||||||
library = find_library(self.server, item)
|
|
||||||
if library:
|
|
||||||
default_args = (self.server, jellyfindb, kodidb, self.direct_path, library)
|
|
||||||
try:
|
try:
|
||||||
if item['Type'] == 'Movie':
|
if item['Type'] == 'Movie':
|
||||||
Movies(*default_args).userdata(item)
|
Movies(*default_args).userdata(item)
|
||||||
|
@ -688,7 +683,7 @@ class UserDataWorker(threading.Thread):
|
||||||
elif item['Type'] == 'AlbumArtist':
|
elif item['Type'] == 'AlbumArtist':
|
||||||
Music(*default_args).albumartist(item)
|
Music(*default_args).albumartist(item)
|
||||||
elif item['Type'] == 'Audio':
|
elif item['Type'] == 'Audio':
|
||||||
Music(*default_args).song(item)
|
Music(*default_args).userdata(item)
|
||||||
except LibraryException as error:
|
except LibraryException as error:
|
||||||
if error.status == 'StopCalled':
|
if error.status == 'StopCalled':
|
||||||
break
|
break
|
||||||
|
|
|
@ -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, 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.utils import find_library
|
||||||
from helper.exceptions import PathValidationException
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
|
@ -54,10 +55,20 @@ class Movies(KodiDb):
|
||||||
obj['MovieId'] = e_item[0]
|
obj['MovieId'] = e_item[0]
|
||||||
obj['FileId'] = e_item[1]
|
obj['FileId'] = e_item[1]
|
||||||
obj['PathId'] = e_item[2]
|
obj['PathId'] = e_item[2]
|
||||||
|
obj['LibraryId'] = e_item[6]
|
||||||
|
obj['LibraryName'] = self.jellyfin_db.get_view_name(obj['LibraryId'])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
LOG.debug("MovieId %s not found", obj['Id'])
|
LOG.debug("MovieId %s not found", obj['Id'])
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
obj['MovieId'] = self.create_entry()
|
obj['MovieId'] = self.create_entry()
|
||||||
|
obj['LibraryId'] = library['Id']
|
||||||
|
obj['LibraryName'] = library['Name']
|
||||||
else:
|
else:
|
||||||
if self.get(*values(obj, QU.get_movie_obj)) is None:
|
if self.get(*values(obj, QU.get_movie_obj)) is None:
|
||||||
|
|
||||||
|
@ -65,8 +76,6 @@ 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'] = self.library['Id']
|
|
||||||
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 []
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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, Local
|
from helper import api, stop, validate, jellyfin_item, values, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.utils import find_library
|
||||||
from helper.exceptions import PathValidationException
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
|
@ -50,9 +51,19 @@ class Music(KodiDb):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj['ArtistId'] = e_item[0]
|
obj['ArtistId'] = e_item[0]
|
||||||
|
obj['LibraryId'] = e_item[6]
|
||||||
|
obj['LibraryName'] = self.jellyfin_db.get_view_name(obj['LibraryId'])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
obj['ArtistId'] = None
|
obj['ArtistId'] = None
|
||||||
|
obj['LibraryId'] = library['Id']
|
||||||
|
obj['LibraryName'] = library['Name']
|
||||||
LOG.debug("ArtistId %s not found", obj['Id'])
|
LOG.debug("ArtistId %s not found", obj['Id'])
|
||||||
else:
|
else:
|
||||||
if self.validate_artist(*values(obj, QU.get_artist_by_id_obj)) is None:
|
if self.validate_artist(*values(obj, QU.get_artist_by_id_obj)) is None:
|
||||||
|
@ -60,8 +71,6 @@ 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'] = self.library['Id']
|
|
||||||
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 [])
|
||||||
|
@ -116,9 +125,19 @@ class Music(KodiDb):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj['AlbumId'] = e_item[0]
|
obj['AlbumId'] = e_item[0]
|
||||||
|
obj['LibraryId'] = e_item[6]
|
||||||
|
obj['LibraryName'] = self.jellyfin_db.get_view_name(obj['LibraryId'])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
obj['AlbumId'] = None
|
obj['AlbumId'] = None
|
||||||
|
obj['LibraryId'] = library['Id']
|
||||||
|
obj['LibraryName'] = library['Name']
|
||||||
LOG.debug("AlbumId %s not found", obj['Id'])
|
LOG.debug("AlbumId %s not found", obj['Id'])
|
||||||
else:
|
else:
|
||||||
if self.validate_album(*values(obj, QU.get_album_by_id_obj)) is None:
|
if self.validate_album(*values(obj, QU.get_album_by_id_obj)) is None:
|
||||||
|
@ -224,9 +243,19 @@ class Music(KodiDb):
|
||||||
obj['SongId'] = e_item[0]
|
obj['SongId'] = e_item[0]
|
||||||
obj['PathId'] = e_item[2]
|
obj['PathId'] = e_item[2]
|
||||||
obj['AlbumId'] = e_item[3]
|
obj['AlbumId'] = e_item[3]
|
||||||
|
obj['LibraryId'] = e_item[6]
|
||||||
|
obj['LibraryName'] = self.jellyfin_db.get_view_name(obj['LibraryId'])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
obj['SongId'] = self.create_entry_song()
|
obj['SongId'] = self.create_entry_song()
|
||||||
|
obj['LibraryId'] = library['Id']
|
||||||
|
obj['LibraryName'] = library['Name']
|
||||||
LOG.debug("SongId %s not found", obj['Id'])
|
LOG.debug("SongId %s not found", obj['Id'])
|
||||||
else:
|
else:
|
||||||
if self.validate_song(*values(obj, QU.get_song_by_id_obj)) is None:
|
if self.validate_song(*values(obj, QU.get_song_by_id_obj)) is None:
|
||||||
|
|
|
@ -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, jellyfin_item, values, Local
|
from helper import api, stop, validate, jellyfin_item, values, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.utils import find_library
|
||||||
from helper.exceptions import PathValidationException
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
|
@ -59,10 +60,20 @@ class MusicVideos(KodiDb):
|
||||||
obj['MvideoId'] = e_item[0]
|
obj['MvideoId'] = e_item[0]
|
||||||
obj['FileId'] = e_item[1]
|
obj['FileId'] = e_item[1]
|
||||||
obj['PathId'] = e_item[2]
|
obj['PathId'] = e_item[2]
|
||||||
|
obj['LibraryId'] = e_item[6]
|
||||||
|
obj['LibraryName'] = self.jellyfin_db.get_view_name(obj['LibraryId'])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
LOG.debug("MvideoId for %s not found", obj['Id'])
|
LOG.debug("MvideoId for %s not found", obj['Id'])
|
||||||
obj['MvideoId'] = self.create_entry()
|
obj['MvideoId'] = self.create_entry()
|
||||||
|
obj['LibraryId'] = library['Id']
|
||||||
|
obj['LibraryName'] = library['Name']
|
||||||
else:
|
else:
|
||||||
if self.get(*values(obj, QU.get_musicvideo_obj)) is None:
|
if self.get(*values(obj, QU.get_musicvideo_obj)) is None:
|
||||||
|
|
||||||
|
|
|
@ -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, values, Local
|
from helper import api, stop, validate, jellyfin_item, values, Local
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
from helper.utils import find_library
|
||||||
from helper.exceptions import PathValidationException
|
from helper.exceptions import PathValidationException
|
||||||
|
|
||||||
from .obj import Objects
|
from .obj import Objects
|
||||||
|
@ -61,10 +62,20 @@ class TVShows(KodiDb):
|
||||||
try:
|
try:
|
||||||
obj['ShowId'] = e_item[0]
|
obj['ShowId'] = e_item[0]
|
||||||
obj['PathId'] = e_item[2]
|
obj['PathId'] = e_item[2]
|
||||||
|
obj['LibraryId'] = e_item[6]
|
||||||
|
obj['LibraryName'] = self.jellyfin_db.get_view_name(obj['LibraryId'])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
LOG.debug("ShowId %s not found", obj['Id'])
|
LOG.debug("ShowId %s not found", obj['Id'])
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
obj['ShowId'] = self.create_entry()
|
obj['ShowId'] = self.create_entry()
|
||||||
|
obj['LibraryId'] = library['Id']
|
||||||
|
obj['LibraryName'] = library['Name']
|
||||||
else:
|
else:
|
||||||
if self.get(*values(obj, QU.get_tvshow_obj)) is None:
|
if self.get(*values(obj, QU.get_tvshow_obj)) is None:
|
||||||
|
|
||||||
|
@ -72,8 +83,6 @@ 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'] = self.library['Id']
|
|
||||||
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'])
|
||||||
|
@ -267,6 +276,12 @@ class TVShows(KodiDb):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
update = False
|
update = False
|
||||||
LOG.debug("EpisodeId %s not found", obj['Id'])
|
LOG.debug("EpisodeId %s not found", obj['Id'])
|
||||||
|
|
||||||
|
library = self.library or find_library(self.server, item)
|
||||||
|
if not library:
|
||||||
|
# This item doesn't belong to a whitelisted library
|
||||||
|
return
|
||||||
|
|
||||||
obj['EpisodeId'] = self.create_entry_episode()
|
obj['EpisodeId'] = self.create_entry_episode()
|
||||||
else:
|
else:
|
||||||
if self.get_episode(*values(obj, QU.get_episode_obj)) is None:
|
if self.get_episode(*values(obj, QU.get_episode_obj)) is None:
|
||||||
|
|
Loading…
Reference in a new issue