def test_notify(self, username, disable_ssl, blacklist_name=None): """ Sends a test notification to trakt with the given authentication info and returns a boolean representing success. api: The api string to use username: The username to use password: The password to use blacklist_name: slug of trakt list used to hide not interested show Returns: True if the request succeeded, False otherwise """ try: trakt_api = TraktAPI(disable_ssl, sickbeard.TRAKT_TIMEOUT) trakt_api.validateAccount() if blacklist_name and blacklist_name is not None: trakt_lists = trakt_api.traktRequest("users/" + username + "/lists") found = False for trakt_list in trakt_lists: if (trakt_list['ids']['slug'] == blacklist_name): return "Test notice sent successfully to Trakt" if not found: return "Trakt blacklist doesn't exists" else: return "Test notice sent successfully to Trakt" except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING) return "Test notice failed to Trakt: %s" % ex(e)
def test_notify(self, username, password, disable_ssl, blacklist_name=None): """ Sends a test notification to trakt with the given authentication info and returns a boolean representing success. api: The api string to use username: The username to use password: The password to use blacklist_name: slug of trakt list used to hide not interested show Returns: True if the request succeeded, False otherwise """ try: trakt_api = TraktAPI(sickbeard.TRAKT_API_KEY, username, password, disable_ssl, sickbeard.TRAKT_TIMEOUT) trakt_api.validateAccount() if blacklist_name and blacklist_name is not None: trakt_lists = trakt_api.traktRequest("users/" + username + "/lists") found = False for trakt_list in trakt_lists: if (trakt_list['ids']['slug'] == blacklist_name): return "Test notice sent successfully to Trakt" if not found: return "Trakt blacklist doesn't exists" else: return "Test notice sent successfully to Trakt" except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING) return "Test notice failed to Trakt: %s" % ex(e)
def update_library(self, ep_obj): """ Sends a request to trakt indicating that the given episode is part of our library. ep_obj: The TVEpisode object to add to trakt """ trakt_id = sickbeard.indexerApi(ep_obj.show.indexer).config['trakt_id'] trakt_api = TraktAPI(sickbeard.TRAKT_API_KEY, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD, sickbeard.TRAKT_DISABLE_SSL_VERIFY, sickbeard.TRAKT_TIMEOUT) if sickbeard.USE_TRAKT: try: # URL parameters data = { 'shows': [{ 'title': ep_obj.show.name, 'year': ep_obj.show.startyear, 'ids': {}, }] } if trakt_id == 'tvdb_id': data['shows'][0]['ids']['tvdb'] = ep_obj.show.indexerid else: data['shows'][0]['ids']['tvrage'] = ep_obj.show.indexerid if sickbeard.TRAKT_SYNC_WATCHLIST: if sickbeard.TRAKT_REMOVE_SERIESLIST: trakt_api.traktRequest("sync/watchlist/remove", data, method='POST') # Add Season and Episode + Related Episodes data['shows'][0]['seasons'] = [{ 'number': ep_obj.season, 'episodes': [] }] for relEp_Obj in [ep_obj] + ep_obj.relatedEps: data['shows'][0]['seasons'][0]['episodes'].append( {'number': relEp_Obj.episode}) if sickbeard.TRAKT_SYNC_WATCHLIST: if sickbeard.TRAKT_REMOVE_WATCHLIST: trakt_api.traktRequest("sync/watchlist/remove", data, method='POST') # update library trakt_api.traktRequest("sync/collection", data, method='POST') except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
def test_notify(self, username, password, disable_ssl): """ Sends a test notification to trakt with the given authentication info and returns a boolean representing success. api: The api string to use username: The username to use password: The password to use Returns: True if the request succeeded, False otherwise """ try: trakt_api = TraktAPI(sickbeard.TRAKT_API_KEY, username, password, disable_ssl, sickbeard.TRAKT_TIMEOUT) trakt_api.validateAccount() return "Test notice sent successfully to Trakt" except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING) return "Test notice failed to Trakt: %s" % ex(e)
def update_library(self, ep_obj): """ Sends a request to trakt indicating that the given episode is part of our library. ep_obj: The TVEpisode object to add to trakt """ trakt_id = sickbeard.indexerApi(ep_obj.show.indexer).config['trakt_id'] trakt_api = TraktAPI(sickbeard.TRAKT_DISABLE_SSL_VERIFY, sickbeard.TRAKT_TIMEOUT) if sickbeard.USE_TRAKT: try: # URL parameters data = { 'shows': [ { 'title': ep_obj.show.name, 'year': ep_obj.show.startyear, 'ids': {}, } ] } if trakt_id == 'tvdb_id': data['shows'][0]['ids']['tvdb'] = ep_obj.show.indexerid else: data['shows'][0]['ids']['tvrage'] = ep_obj.show.indexerid if sickbeard.TRAKT_SYNC_WATCHLIST: if sickbeard.TRAKT_REMOVE_SERIESLIST: trakt_api.traktRequest("sync/watchlist/remove", data, method='POST') # Add Season and Episode + Related Episodes data['shows'][0]['seasons']=[{'number': ep_obj.season,'episodes': [] }] for relEp_Obj in [ep_obj] + ep_obj.relatedEps: data['shows'][0]['seasons'][0]['episodes'].append({'number': relEp_Obj.episode}) if sickbeard.TRAKT_SYNC_WATCHLIST: if sickbeard.TRAKT_REMOVE_WATCHLIST: trakt_api.traktRequest("sync/watchlist/remove", data, method='POST') # update library trakt_api.traktRequest("sync/collection", data, method='POST') except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
def update_watchlist (self, show_obj = None, s = None, e = None, data_show = None, data_episode = None, update = "add"): """ Sends a request to trakt indicating that the given episode is part of our library. show_obj: The TVShow object to add to trakt s: season number e: episode number data_show: structured object of shows traktv type data_episode: structured object of episodes traktv type update: type o action add or remove """ trakt_api = TraktAPI(sickbeard.TRAKT_DISABLE_SSL_VERIFY, sickbeard.TRAKT_TIMEOUT) if sickbeard.USE_TRAKT: data = {} try: # URL parameters if show_obj is not None: trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id'] data = { 'shows': [ { 'title': show_obj.name, 'year': show_obj.startyear, 'ids': {}, } ] } if trakt_id == 'tvdb_id': data['shows'][0]['ids']['tvdb'] = show_obj.indexerid else: data['shows'][0]['ids']['tvrage'] = show_obj.indexerid elif data_show is not None: data.update(data_show) else: logger.log(u"there's a coding problem contact developer. It's needed to be provided at lest one of the two: data_show or show_obj", logger.WARNING) return False if data_episode is not None: data['shows'][0].update(data_episode) elif s is not None: # traktv URL parameters season = { 'season': [ { 'number': s, } ] } if e is not None: # traktv URL parameters episode = { 'episodes': [ { 'number': e } ] } season['season'][0].update(episode) data['shows'][0].update(season) trakt_url = "sync/watchlist" if update=="remove": trakt_url += "/remove" trakt_api.traktRequest(trakt_url, data, method='POST') except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING) return False return True
def update_library(self, ep_obj): """ Sends a request to trakt indicating that the given episode is part of our library. ep_obj: The TVEpisode object to add to trakt """ trakt_id = sickbeard.indexerApi(ep_obj.show.indexer).config['trakt_id'] trakt_api = TraktAPI(sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD) if sickbeard.USE_TRAKT: try: # URL parameters data = { 'title': ep_obj.show.name, 'year': ep_obj.show.startyear, 'episodes': [{ 'season': ep_obj.season, 'episode': ep_obj.episode }] } if trakt_id == 'tvdb_id': data[trakt_id] = ep_obj.show.indexerid # update library trakt_api.traktRequest("show/episode/library/%APIKEY%", data, method='POST') # remove from watchlist if sickbeard.TRAKT_REMOVE_WATCHLIST: trakt_api.traktRequest("show/episode/unwatchlist/%APIKEY%", data, method='POST') if sickbeard.TRAKT_REMOVE_SERIESLIST: data = { 'shows': [ { 'title': ep_obj.show.name, 'year': ep_obj.show.startyear } ] } if trakt_id == 'tvdb_id': data['shows'][0][trakt_id] = ep_obj.show.indexerid trakt_api.traktRequest("show/unwatchlist/%APIKEY%", data, method='POST') # Remove all episodes from episode watchlist # Start by getting all episodes in the watchlist watchlist = trakt_api.traktRequest("user/watchlist/episodes.json/%APIKEY%/%USER%") # Convert watchlist to only contain current show if watchlist: for show in watchlist: if show[trakt_id] == ep_obj.show.indexerid: data_show = { 'title': show['title'], trakt_id: show[trakt_id], 'episodes': [] } # Add series and episode (number) to the array for episodes in show['episodes']: ep = {'season': episodes['season'], 'episode': episodes['number']} data_show['episodes'].append(ep) trakt_api.traktRequest("show/episode/unwatchlist/%APIKEY%", data_show, method='POST') except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
def update_library(self, ep_obj): """ Sends a request to trakt indicating that the given episode is part of our library. ep_obj: The TVEpisode object to add to trakt """ trakt_id = sickbeard.indexerApi(ep_obj.show.indexer).config['trakt_id'] trakt_api = TraktAPI(sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD) if sickbeard.USE_TRAKT: try: # URL parameters data = { 'title': ep_obj.show.name, 'year': ep_obj.show.startyear, 'episodes': [{ 'season': ep_obj.season, 'episode': ep_obj.episode }] } if trakt_id == 'tvdb_id': data[trakt_id] = ep_obj.show.indexerid # update library trakt_api.traktRequest("show/episode/library/%APIKEY%", data) # remove from watchlist if sickbeard.TRAKT_REMOVE_WATCHLIST: trakt_api.traktRequest("show/episode/unwatchlist/%APIKEY%", data) if sickbeard.TRAKT_REMOVE_SERIESLIST: data = { 'shows': [ { 'title': ep_obj.show.name, 'year': ep_obj.show.startyear } ] } if trakt_id == 'tvdb_id': data['shows'][0][trakt_id] = ep_obj.show.indexerid trakt_api.traktRequest("show/unwatchlist/%APIKEY%", data) # Remove all episodes from episode watchlist # Start by getting all episodes in the watchlist watchlist = trakt_api.traktRequest("user/watchlist/episodes.json/%APIKEY%/%USER%") # Convert watchlist to only contain current show if watchlist: for show in watchlist: if show[trakt_id] == ep_obj.show.indexerid: data_show = { 'title': show['title'], trakt_id: show[trakt_id], 'episodes': [] } # Add series and episode (number) to the array for episodes in show['episodes']: ep = {'season': episodes['season'], 'episode': episodes['number']} data_show['episodes'].append(ep) trakt_api.traktRequest("show/episode/unwatchlist/%APIKEY%", data_show) except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
def update_watchlist(self, show_obj=None, s=None, e=None, data_show=None, data_episode=None, update="add"): """ Sends a request to trakt indicating that the given episode is part of our library. show_obj: The TVShow object to add to trakt s: season number e: episode number data_show: structured object of shows traktv type data_episode: structured object of episodes traktv type update: type o action add or remove """ trakt_api = TraktAPI(sickbeard.TRAKT_API_KEY, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD) if sickbeard.USE_TRAKT: data = {} try: # URL parameters if show_obj is not None: trakt_id = sickbeard.indexerApi( show_obj.indexer).config['trakt_id'] data = { 'shows': [{ 'title': show_obj.name, 'year': show_obj.startyear, 'ids': {}, }] } if trakt_id == 'tvdb_id': data['shows'][0]['ids']['tvdb'] = show_obj.indexerid else: data['shows'][0]['ids']['tvrage'] = show_obj.indexerid elif data_show is not None: data.update(data_show) else: logger.log( u"there's a coding problem contact developer. It's needed to be provided at lest one of the two: data_show or show_obj", logger.WARNING) return False if data_episode is not None: data['shows'][0].update(data_episode) elif s is not None: # traktv URL parameters season = { 'season': [{ 'number': s, }] } if e is not None: # traktv URL parameters episode = {'episodes': [{'number': e}]} season['season'][0].update(episode) data['shows'][0].update(season) trakt_url = "sync/watchlist" if update == "remove": trakt_url += "/remove" trakt_api.traktRequest(trakt_url, data, method='POST') except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING) return False return True