From 314016e1faf218c6e5b2bd27473b3f26dac17d7b Mon Sep 17 00:00:00 2001 From: Jason Mehring Date: Fri, 13 Sep 2013 03:28:03 -0400 Subject: [PATCH] (WIP) Started intergrating xem --- couchpotato/core/media/show/_base/main.py | 60 ++++++++++++------- .../core/media/show/library/episode/main.py | 5 +- .../core/media/show/library/season/main.py | 4 +- .../core/providers/info/thetvdb/main.py | 9 ++- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/couchpotato/core/media/show/_base/main.py b/couchpotato/core/media/show/_base/main.py index 2d11a67b..38077e67 100644 --- a/couchpotato/core/media/show/_base/main.py +++ b/couchpotato/core/media/show/_base/main.py @@ -82,16 +82,6 @@ class ShowBase(MediaBase): def add(self, params = {}, force_readd = True, search_after = True, update_library = False, status_id = None): """ - 1. Add Show - 2. Add All Episodes - 3. Add All Seasons - - Notes, not to forget: - - relate parent and children, possible grandparent to grandchild so episodes know it belong to show, etc - - looks like we dont send info to library; it comes later - - change references to plot to description - - change Model to Media - params {'category_id': u'-1', 'identifier': u'tt1519931', @@ -102,10 +92,21 @@ class ShowBase(MediaBase): log.debug("show.add") # Add show parent to db first; need to update library so maps will be in place (if any) - parent = self.addToDatabase(params = params, update_library = True, type = 'show') + parent = self.addToDatabase(params = params, update_library = True, type = 'show') + + # TODO: add by airdate + + # Add by Season/Episode numbers + self.addBySeasonEpisode(parent, + params = params, + force_readd = force_readd, + search_after = search_after, + update_library = update_library, + status_id = status_id + ) + + def addBySeasonEpisode(self, parent, params = {}, force_readd = True, search_after = True, update_library = False, status_id = None): identifier = params.get('id') - - # 'tvdb' will always be the master for our purpose. All mapped data can be mapped # to another source for downloading, but it will always be remapped back to tvdb numbering # when renamed so media can be used in media players that use tvdb for info provider @@ -113,12 +114,15 @@ class ShowBase(MediaBase): # This currently means the episode must actually exist in tvdb in order to be found but # the numbering can be different - # XXX: - # Map Notes: - # (in progress...) - # map = parent['library']['info']['map'] #master = 'tvdb' #destination = 'scene' + #destination = 'anidb' + #destination = 'rage' + #destination = 'trakt' + # TODO: auto mode. if anime exists use it. if scene exists use it else use tvdb + + # XXX: We should abort adding show, etc if either tvdb or xem is down or we will have incorrent mappings + # I think if tvdb gets error we wont have anydata anyway, but we must make sure XEM returns!!!! # Only the master should return results here; all other info providers should just return False # since we are just interested in the structure at this point. @@ -131,14 +135,16 @@ class ShowBase(MediaBase): season_id = season.get('id', None) if season_id is None: continue + season_params = {'season_identifier': season_id} # Calling all info providers; merge your info now for individual season - single_season = fireEvent('season.info', merge = True, identifier = identifier, season_identifier = season_id) + single_season = fireEvent('season.info', merge = True, identifier = identifier, params = season_params) single_season['title'] = single_season.get('original_title', None) single_season['identifier'] = season_id single_season['parent_identifier'] = identifier s = self.addToDatabase(params = single_season, type = "season") - episodes = fireEvent('episode.info', merge = True, identifier = identifier, season_identifier = season_id) + episode_params = {'season_identifier': season_id} + episodes = fireEvent('episode.info', merge = True, identifier = identifier, params = episode_params) if episodes is not None: for episode in episodes: # Make sure we are only dealing with 'tvdb' responses at this point @@ -146,10 +152,22 @@ class ShowBase(MediaBase): continue episode_id = episode.get('id', None) if episode_id is None: continue + try: + episode_number = int(episode.get('episodenumber', None)) + except (ValueError, TypeError): + continue + try: + absolute_number = int(episode.get('absolute_number', None)) + except (ValueError, TypeError): + absolute_number = None + episode_params = {'season_identifier': season_id, + 'episode_identifier': episode_id, + 'episode': episode_number} + if absolute_number: + episode_params['absolute'] = absolute_number # Calling all info providers; merge your info now for individual episode - single_episode = fireEvent('episode.info', merge = True, identifier = identifier, - season_identifier = season_id, episode_identifier = episode_id) + single_episode = fireEvent('episode.info', merge = True, identifier = identifier, params = episode_params) single_episode['title'] = single_episode.get('original_title', None) single_episode['identifier'] = episode_id single_episode['parent_identifier'] = single_season['identifier'] diff --git a/couchpotato/core/media/show/library/episode/main.py b/couchpotato/core/media/show/library/episode/main.py index bb7ac477..bc2a6060 100644 --- a/couchpotato/core/media/show/library/episode/main.py +++ b/couchpotato/core/media/show/library/episode/main.py @@ -88,8 +88,9 @@ class EpisodeLibraryPlugin(LibraryBase): if library.status_id == done_status.get('id') and not force: do_update = False - info = fireEvent('episode.info', merge = True, season_identifier = parent_identifier, \ - episode_identifier = identifier) + episode_params = {'season_identifier': parent_identifier, + 'episode_identifier': identifier} + info = fireEvent('episode.info', merge = True, params = episode_params) # Don't need those here try: del info['in_wanted'] diff --git a/couchpotato/core/media/show/library/season/main.py b/couchpotato/core/media/show/library/season/main.py index b3866d3e..3912c5f0 100644 --- a/couchpotato/core/media/show/library/season/main.py +++ b/couchpotato/core/media/show/library/season/main.py @@ -88,8 +88,8 @@ class SeasonLibraryPlugin(LibraryBase): if library.status_id == done_status.get('id') and not force: do_update = False - info = fireEvent('season.info', merge = True, identifier = parent_identifier, \ - season_identifier = identifier) + season_params = {'season_identifier': identifier} + info = fireEvent('season.info', merge = True, identifier = parent_identifier, params = season_params) # Don't need those here try: del info['in_wanted'] diff --git a/couchpotato/core/providers/info/thetvdb/main.py b/couchpotato/core/providers/info/thetvdb/main.py index e0af4033..f0c7fc36 100644 --- a/couchpotato/core/providers/info/thetvdb/main.py +++ b/couchpotato/core/providers/info/thetvdb/main.py @@ -110,13 +110,15 @@ class TheTVDb(ShowProvider): return result - def getSeasonInfo(self, identifier=None, season_identifier=None): + def getSeasonInfo(self, identifier = None, params = {}): """Either return a list of all seasons or a single season by number. identifier is the show 'id' """ if not identifier: return False + season_identifier = params.get('season_identifier', None) + # season_identifier must contain the 'show id : season number' since there is no tvdb id # for season and we need a reference to both the show id and season number if season_identifier: @@ -147,10 +149,13 @@ class TheTVDb(ShowProvider): self.setCache(cache_key, result) return result - def getEpisodeInfo(self, identifier=None, season_identifier=None, episode_identifier=None): + def getEpisodeInfo(self, identifier = None, params = {}): """Either return a list of all episodes or a single episode. If episode_identifer contains an episode number to search for """ + season_identifier = params.get('season_identifier', None) + episode_identifier = params.get('episode_identifier', None) + if not identifier and season_identifier is None: return False