From 9933480f8d8ad231a7040c89d6c666731d60ea38 Mon Sep 17 00:00:00 2001 From: bernimoses Date: Thu, 3 Oct 2019 21:30:05 +0200 Subject: [PATCH] Add tmdb provider sync. --- resources/lib/itemtypes/movies.py | 15 ++++++++++++++ resources/lib/itemtypes/tvshows.py | 32 ++++++++++++++++++++++++++++++ resources/lib/plex_api/base.py | 3 +++ resources/lib/utils.py | 1 + 4 files changed, 51 insertions(+) diff --git a/resources/lib/itemtypes/movies.py b/resources/lib/itemtypes/movies.py index 7e831c40..ede1c99e 100644 --- a/resources/lib/itemtypes/movies.py +++ b/resources/lib/itemtypes/movies.py @@ -90,6 +90,14 @@ class Movie(ItemBase): api.provider('imdb'), "imdb", uniqueid) + elif api.provider('tmdb') is not None: + uniqueid = self.kodidb.get_uniqueid(kodi_id, + v.KODI_TYPE_MOVIE) + self.kodidb.update_uniqueid(kodi_id, + v.KODI_TYPE_MOVIE, + api.provider('tmdb'), + "tmdb", + uniqueid) else: self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_MOVIE) uniqueid = -1 @@ -119,6 +127,13 @@ class Movie(ItemBase): v.KODI_TYPE_MOVIE, api.provider('imdb'), "imdb") + elif api.provider('tmdb') is not None: + uniqueid = self.kodidb.add_uniqueid_id() + self.kodidb.add_uniqueid(uniqueid, + kodi_id, + v.KODI_TYPE_MOVIE, + api.provider('tmdb'), + "tmdb") else: uniqueid = -1 self.kodidb.add_people(kodi_id, diff --git a/resources/lib/itemtypes/tvshows.py b/resources/lib/itemtypes/tvshows.py index f2914e42..3f74e39e 100644 --- a/resources/lib/itemtypes/tvshows.py +++ b/resources/lib/itemtypes/tvshows.py @@ -202,6 +202,14 @@ class Show(TvShowMixin, ItemBase): api.provider('tvdb'), 'tvdb', uniqueid) + elif api.provider('tmdb') is not None: + uniqueid = self.kodidb.get_uniqueid(kodi_id, + v.KODI_TYPE_SHOW) + self.kodidb.update_uniqueid(kodi_id, + v.KODI_TYPE_SHOW, + api.provider('tmdb'), + 'tmdb', + uniqueid) else: self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_SHOW) uniqueid = -1 @@ -243,6 +251,13 @@ class Show(TvShowMixin, ItemBase): v.KODI_TYPE_SHOW, api.provider('tvdb'), 'tvdb') + if api.provider('tmdb'): + uniqueid = self.kodidb.add_uniqueid_id() + self.kodidb.add_uniqueid(uniqueid, + kodi_id, + v.KODI_TYPE_SHOW, + api.provider('tmdb'), + 'tmdb') else: uniqueid = -1 self.kodidb.add_people(kodi_id, @@ -486,6 +501,14 @@ class Episode(TvShowMixin, ItemBase): api.provider('tvdb'), "tvdb", uniqueid) + elif api.provider('tmdb'): + uniqueid = self.kodidb.get_uniqueid(kodi_id, + v.KODI_TYPE_EPISODE) + self.kodidb.update_uniqueid(kodi_id, + v.KODI_TYPE_EPISODE, + api.provider('tmdb'), + "tmdb", + uniqueid) else: self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_EPISODE) uniqueid = -1 @@ -564,6 +587,15 @@ class Episode(TvShowMixin, ItemBase): v.KODI_TYPE_EPISODE, api.provider('tvdb'), "tvdb") + elif api.provider('tmdb'): + uniqueid = self.kodidb.add_uniqueid_id() + self.kodidb.add_uniqueid(uniqueid, + kodi_id, + v.KODI_TYPE_EPISODE, + api.provider('tmdb'), + "tmdb") + else: + uniqueid = -1 self.kodidb.add_people(kodi_id, v.KODI_TYPE_EPISODE, api.people()) diff --git a/resources/lib/plex_api/base.py b/resources/lib/plex_api/base.py index 096cd47e..e14bcf21 100644 --- a/resources/lib/plex_api/base.py +++ b/resources/lib/plex_api/base.py @@ -552,6 +552,9 @@ class Base(object): elif providername == 'tvdb': # originally e.g. com.plexapp.agents.thetvdb://276564?lang=en regex = utils.REGEX_TVDB + elif providername == 'tmdb': + # originally e.g. com.plexapp.agents.themoviedb://603?lang=en + regex = utils.REGEX_TMDB else: raise NotImplementedError('Not implemented: %s' % providername) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index ad2d25ce..23e64fa4 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -49,6 +49,7 @@ REGEX_PLEX_DIRECT = re.compile(r'''\.plex\.direct:\d+$''') # Plex API REGEX_IMDB = re.compile(r'''/(tt\d+)''') REGEX_TVDB = re.compile(r'''thetvdb:\/\/(.+?)\?''') +REGEX_TMDB = re.compile(r'''themoviedb:\/\/(.+?)\?''') # Plex music REGEX_MUSICPATH = re.compile(r'''^\^(.+)\$$''') # Grab Plex id from an URL-encoded string