From b8b5947ae65a2e673fe775c84b1b7c3d92d8b4a8 Mon Sep 17 00:00:00 2001 From: echel0n Date: Wed, 30 Jul 2014 16:33:28 -0700 Subject: [PATCH] Fix for trakt.tv issues when adding/removing/syncing shows. Fix for indexer mapper to return a result no matter what. --- sickbeard/helpers.py | 6 +++- sickbeard/providers/newznab.py | 12 ++++---- sickbeard/traktChecker.py | 53 ++++++++++++++-------------------- sickbeard/webapi.py | 9 ++---- 4 files changed, 35 insertions(+), 45 deletions(-) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 5446af69..9027f7ce 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1139,7 +1139,11 @@ def extractZip(archive, targetDir): def mapIndexersToShow(showObj): - mapped = {showObj.indexer: showObj.indexerid} + mapped = {} + + # init mapped indexers object + for indexer in sickbeard.indexerApi().indexers: + mapped[indexer] = showObj.indexerid if int(indexer) == int(showObj.indexer) else 0 myDB = db.DBConnection() sqlResults = myDB.select( diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index 2a8f536d..0a0494c1 100755 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -98,9 +98,9 @@ class NewznabProvider(generic.NZBProvider): cur_params['season'] = str(ep_obj.scene_season) # search - mindexers = helpers.mapIndexersToShow(ep_obj.show) - if 2 in mindexers: - cur_params['rid'] = mindexers[2] + rid = helpers.mapIndexersToShow(ep_obj.show)[2] + if rid: + cur_params['rid'] = rid to_return.append(cur_params) else: # add new query strings for exceptions @@ -131,9 +131,9 @@ class NewznabProvider(generic.NZBProvider): params['ep'] = ep_obj.scene_episode # search - mindexers = helpers.mapIndexersToShow(ep_obj.show) - if 2 in mindexers: - params['rid'] = mindexers[2] + rid = helpers.mapIndexersToShow(ep_obj.show)[2] + if rid: + params['rid'] = rid to_return.append(params) else: # add new query strings for exceptions diff --git a/sickbeard/traktChecker.py b/sickbeard/traktChecker.py index a1c876d9..c9a138d3 100644 --- a/sickbeard/traktChecker.py +++ b/sickbeard/traktChecker.py @@ -60,29 +60,23 @@ class TraktChecker(): return filter(lambda x: int(indexerid) in [int(x['tvdb_id']) or 0, int(x['tvrage_id'])] or 0, library) def syncLibrary(self): - logger.log(u"Syncing library to Trakt.tv show library", logger.DEBUG) - if sickbeard.showList: - for myShow in sickbeard.showList: - self.addShowToTraktLibrary(myShow) + logger.log(u"Syncing Trakt.tv show library", logger.DEBUG) + + for myShow in sickbeard.showList: + self.addShowToTraktLibrary(myShow) def removeShowFromTraktLibrary(self, show_obj): + data = {} if self.findShow(show_obj.indexer, show_obj.indexerid): # URL parameters - data = {} - if show_obj.indexer == 1: - data['tvdb_id'] = show_obj.indexerid - data['title'] = show_obj.name - data['year'] = show_obj.startyear + data['tvdb_id'] = helpers.mapIndexersToShow(show_obj)[1] + data['title'] = show_obj.name + data['year'] = show_obj.startyear - elif show_obj.indexer == 2: - data['tvrage_id'] = show_obj.indexerid - data['title'] = show_obj.name - data['year'] = show_obj.startyear - - if data is not None: - logger.log(u"Removing " + show_obj.name + " from trakt.tv library", logger.DEBUG) - TraktCall("show/unlibrary/%API%", sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD, - data) + if len(data): + logger.log(u"Removing " + show_obj.name + " from trakt.tv library", logger.DEBUG) + TraktCall("show/unlibrary/%API%", sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD, + data) def addShowToTraktLibrary(self, show_obj): """ @@ -91,23 +85,18 @@ class TraktChecker(): show_obj: The TVShow object to add to trakt """ + data = {} + if not self.findShow(show_obj.indexer, show_obj.indexerid): # URL parameters - data = {} - if show_obj.indexer == 1: - data['tvdb_id'] = show_obj.indexerid - data['title'] = show_obj.name - data['year'] = show_obj.startyear + data['tvdb_id'] = helpers.mapIndexersToShow(show_obj)[1] + data['title'] = show_obj.name + data['year'] = show_obj.startyear - elif show_obj.indexer == 2: - data['tvrage_id'] = show_obj.indexerid - data['title'] = show_obj.name - data['year'] = show_obj.startyear - - if data: - logger.log(u"Adding " + show_obj.name + " to trakt.tv library", logger.DEBUG) - TraktCall("show/library/%API%", sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD, - data) + if len(data): + logger.log(u"Adding " + show_obj.name + " to trakt.tv library", logger.DEBUG) + TraktCall("show/library/%API%", sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD, + data) def updateShows(self): logger.log(u"Starting trakt show watchlist check", logger.DEBUG) diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index 16c07f2f..70a1c911 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -1720,8 +1720,6 @@ class CMD_Show(ApiCall): if not showObj: return _responds(RESULT_FAILURE, msg="Show not found") - mindexers = helpers.mapIndexersToShow(showObj) - showDict = {} showDict["season_list"] = CMD_ShowSeasonList(self.handler, (), {"indexerid": self.indexerid}).run()["data"] showDict["cache"] = CMD_ShowCache(self.handler, (), {"indexerid": self.indexerid}).run()["data"] @@ -1752,7 +1750,7 @@ class CMD_Show(ApiCall): showDict["anime"] = showObj.anime #clean up tvdb horrible airs field showDict["airs"] = str(showObj.airs).replace('am', ' AM').replace('pm', ' PM').replace(' ', ' ') - showDict["tvrage_id"] = mindexers[2] if 2 in mindexers else 0 + showDict["tvrage_id"] = helpers.mapIndexersToShow(showObj)[2] showDict["tvrage_name"] = showObj.name showDict["network"] = showObj.network if not showDict["network"]: @@ -2521,7 +2519,6 @@ class CMD_Shows(ApiCall): if self.paused != None and bool(self.paused) != bool(curShow.paused): continue - mindexers = helpers.mapIndexersToShow(curShow) showDict = { "paused": curShow.paused, "quality": _get_quality_string(curShow.quality), @@ -2530,8 +2527,8 @@ class CMD_Shows(ApiCall): "sports": curShow.sports, "anime": curShow.anime, "indexerid": curShow.indexerid, - "tvdbid": mindexers[1] if 1 in mindexers else 0, - "tvrage_id": mindexers[2] if 2 in mindexers else 0, + "tvdbid": helpers.mapIndexersToShow(curShow)[1], + "tvrage_id": helpers.mapIndexersToShow(curShow)[2], "tvrage_name": curShow.name, "network": curShow.network, "show_name": curShow.name,