From 90adb873d80e9f2748ae323f18dca1b6e28d06b8 Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 19 Dec 2024 07:56:20 +0100 Subject: [PATCH] Improve sync speed slightly and fix compatibility: Be more careful when calling TMDB Kodi-Addon methods fixup fixup --- .../library_sync/additional_metadata_tmdb.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/resources/lib/library_sync/additional_metadata_tmdb.py b/resources/lib/library_sync/additional_metadata_tmdb.py index e66510d27..5a6000f37 100644 --- a/resources/lib/library_sync/additional_metadata_tmdb.py +++ b/resources/lib/library_sync/additional_metadata_tmdb.py @@ -3,6 +3,7 @@ import logging import os import sys +import inspect import xbmcvfs import xbmcaddon @@ -21,24 +22,34 @@ logger = logging.getLogger('PLEX.metadata_movies') PREFER_KODI_COLLECTION_ART = utils.settings('PreferKodiCollectionArt') == 'false' + +TMDB_SETTINGS = xbmcaddon.Addon(id='metadata.themoviedb.org.python') +TMDB_MOVIESCRAPER_API = inspect.signature(tmdb.TMDBMovieScraper).parameters +if len(TMDB_MOVIESCRAPER_API) not in (4, 5): + logger.error('tmdb.TMDBMovieScraper api changed to this: %s', + inspect.signature(tmdb.TMDBMovieScraper).parameters) + raise RuntimeError('tmdb.TMDBMovieScraper api changed') + TMDB_SUPPORTED_IDS = ('tmdb', 'imdb') +def number_of_function_args(func): + """Returns the number of arguments the function func accepts""" + return len(inspect.signature(func).parameters) + + def get_tmdb_scraper(settings): language = settings.getSettingString('language') certcountry = settings.getSettingString('tmdbcertcountry') - # Simplify this in the future - # See https://github.com/croneter/PlexKodiConnect/issues/1657 - search_language = settings.getSettingString('searchlanguage') - if search_language: + if len(TMDB_MOVIESCRAPER_API) == 5: + search_language = settings.getSettingString('searchlanguage') return tmdb.TMDBMovieScraper(settings, language, certcountry, search_language) else: return tmdb.TMDBMovieScraper(settings, language, certcountry) def get_tmdb_details(unique_ids): - settings = xbmcaddon.Addon(id='metadata.themoviedb.org.python') - details = get_tmdb_scraper(settings).get_details(unique_ids) + details = get_tmdb_scraper(TMDB_SETTINGS).get_details(unique_ids) if 'error' in details: logger.debug('Could not get tmdb details for %s. Error: %s', unique_ids, details)