Skip to content

Commit

Permalink
Improve sync speed slightly and fix compatibility: Be more careful wh…
Browse files Browse the repository at this point in the history
…en calling TMDB Kodi-Addon methods

fixup

fixup
  • Loading branch information
Croneter committed Dec 19, 2024
1 parent 1ac868e commit 90adb87
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions resources/lib/library_sync/additional_metadata_tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import sys
import inspect

import xbmcvfs
import xbmcaddon
Expand All @@ -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)
Expand Down

0 comments on commit 90adb87

Please sign in to comment.