From 66787dec3e8590bcc945001b0c3809caf4cac022 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 21 Feb 2021 16:58:02 +0100 Subject: [PATCH] Python 2 backport of code --- resources/lib/itemtypes/movies_tmdb.py | 13 +++++++++---- resources/lib/kodi_db/video.py | 6 ++++-- resources/lib/library_sync/additional_metadata.py | 1 + .../lib/library_sync/additional_metadata_tmdb.py | 15 +++++++++------ resources/lib/migration.py | 11 +++++++++++ 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/resources/lib/itemtypes/movies_tmdb.py b/resources/lib/itemtypes/movies_tmdb.py index 05f4e6da..1dee431a 100644 --- a/resources/lib/itemtypes/movies_tmdb.py +++ b/resources/lib/itemtypes/movies_tmdb.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, unicode_literals import logging import os import sys @@ -9,8 +10,10 @@ import xbmcaddon # Import the existing Kodi add-on metadata.themoviedb.org.python __ADDON__ = xbmcaddon.Addon(id='metadata.themoviedb.org.python') -__TEMP_PATH__ = os.path.join(__ADDON__.getAddonInfo('path'), 'python', 'lib') -__BASE__ = xbmcvfs.translatePath(__TEMP_PATH__) +__TEMP_PATH__ = os.path.join(__ADDON__.getAddonInfo('path').decode('utf-8'), + 'python', + 'lib') +__BASE__ = xbmcvfs.translatePath(__TEMP_PATH__.encode('utf-8')).decode('utf-8') sys.path.append(__BASE__) import tmdbscraper.tmdb as tmdb @@ -18,8 +21,8 @@ logger = logging.getLogger('PLEX.movies_tmdb') def get_tmdb_scraper(settings): - language = settings.getSettingString('language') - certcountry = settings.getSettingString('tmdbcertcountry') + language = settings.getSettingString('language').decode('utf-8') + certcountry = settings.getSettingString('tmdbcertcountry').decode('utf-8') return tmdb.TMDBMovieScraper(__ADDON__, language, certcountry) @@ -27,8 +30,10 @@ def get_tmdb_scraper(settings): # for every single movie __SCRAPER__ = get_tmdb_scraper(__ADDON__) + def get_tmdb_details(unique_ids): details = __SCRAPER__.get_details(unique_ids) + LOG.error('details type. %s', type(details)) if 'error' in details: logger.debug('Could not get tmdb details for %s. Error: %s', unique_ids, details) diff --git a/resources/lib/kodi_db/video.py b/resources/lib/kodi_db/video.py index 0b64b115..15ed224c 100644 --- a/resources/lib/kodi_db/video.py +++ b/resources/lib/kodi_db/video.py @@ -487,7 +487,8 @@ class KodiVideoDB(common.KodiDBBase): self.cursor.execute('SELECT c19 FROM movie WHERE idMovie=?', (kodi_id, )) else: - raise NotImplementedError(f'trailers for {kodi_type} not implemented') + raise NotImplementedError('trailers for %s not implemented' + % kodi_type) try: return self.cursor.fetchone()[0] except TypeError: @@ -502,7 +503,8 @@ class KodiVideoDB(common.KodiDBBase): self.cursor.execute('UPDATE movie SET c19=? WHERE idMovie=?', (url, kodi_id)) else: - raise NotImplementedError(f'trailers for {kodi_type} not implemented') + raise NotImplementedError('trailers for not implemented' + % kodi_type) @db.catch_operationalerrors def modify_streams(self, fileid, streamdetails=None, runtime=None): diff --git a/resources/lib/library_sync/additional_metadata.py b/resources/lib/library_sync/additional_metadata.py index 70f5b575..6d245414 100644 --- a/resources/lib/library_sync/additional_metadata.py +++ b/resources/lib/library_sync/additional_metadata.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, unicode_literals from logging import getLogger from . import additional_metadata_tmdb diff --git a/resources/lib/library_sync/additional_metadata_tmdb.py b/resources/lib/library_sync/additional_metadata_tmdb.py index 4afec456..1d7c324a 100644 --- a/resources/lib/library_sync/additional_metadata_tmdb.py +++ b/resources/lib/library_sync/additional_metadata_tmdb.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, unicode_literals import logging import os import sys @@ -14,8 +15,10 @@ from .. import itemtypes, plex_functions as PF, utils, variables as v # Import the existing Kodi add-on metadata.themoviedb.org.python __ADDON__ = xbmcaddon.Addon(id='metadata.themoviedb.org.python') -__TEMP_PATH__ = os.path.join(__ADDON__.getAddonInfo('path'), 'python', 'lib') -__BASE__ = xbmcvfs.translatePath(__TEMP_PATH__) +__TEMP_PATH__ = os.path.join(__ADDON__.getAddonInfo('path').decode('utf-8'), + 'python', + 'lib') +__BASE__ = xbmcvfs.translatePath(__TEMP_PATH__.encode('utf-8')).decode('utf-8') sys.path.append(__BASE__) import tmdbscraper.tmdb as tmdb @@ -25,8 +28,8 @@ TMDB_SUPPORTED_IDS = ('tmdb', 'imdb') def get_tmdb_scraper(settings): - language = settings.getSettingString('language') - certcountry = settings.getSettingString('tmdbcertcountry') + language = settings.getSettingString('language').decode('utf-8') + certcountry = settings.getSettingString('tmdbcertcountry').decode('utf-8') return tmdb.TMDBMovieScraper(settings, language, certcountry) @@ -51,7 +54,7 @@ def process_trailers(plex_id, plex_type, refresh=False): with KodiVideoDB() as kodidb: trailer = kodidb.get_trailer(db_item['kodi_id'], db_item['kodi_type']) - if trailer and (trailer.startswith(f'plugin://{v.ADDON_ID}') or + if trailer and (trailer.startswith('plugin://' + v.ADDON_ID) or not refresh): # No need to get a trailer return @@ -61,7 +64,7 @@ def process_trailers(plex_id, plex_type, refresh=False): xml[0].attrib except (TypeError, IndexError, AttributeError): logger.warn('Could not get metadata for %s. Skipping that %s ' - 'for now', plex_id, plex_type) + 'for now', plex_id, plex_type) done = False return api = API(xml[0]) diff --git a/resources/lib/migration.py b/resources/lib/migration.py index e99e3210..7d2475c9 100644 --- a/resources/lib/migration.py +++ b/resources/lib/migration.py @@ -99,4 +99,15 @@ def check_migration(): utils.settings('accessToken', value='') utils.settings('plexAvatar', value='') + # Need to delete the UNIQUE index that prevents creating several + # playlist entries with the same kodi_hash + if not utils.compare_version(last_migration, '2.12.17'): + LOG.info('Migrating to version 2.12.16') + # Add an additional column `trailer_synced` in the Plex movie table + from .plex_db import PlexDB + with PlexDB() as plexdb: + query = 'ALTER TABLE movie ADD trailer_synced BOOLEAN' + plexdb.cursor.execute(query) + # Index will be automatically recreated on next PKC startup + utils.settings('last_migrated_PKC_version', value=v.ADDON_VERSION)