def addShowToBlacklist(self, seriesid): # URL parameters data = {'shows': [{'ids': {'tvdb': seriesid}}]} show_name = get_showname_from_indexer(INDEXER_TVDBV2, seriesid) try: trakt_user = get_trakt_user() blacklist = trakt_user.get_list(app.TRAKT_BLACKLIST_NAME) if not blacklist: ui.notifications.error( 'Warning', 'Could not find blacklist {blacklist} for user {user}.'.format( blacklist=app.TRAKT_BLACKLIST_NAME, user=trakt_user.username ) ) log.warning( 'Could not find blacklist {blacklist} for user {user}.', {'blacklist': app.TRAKT_BLACKLIST_NAME, 'user': trakt_user.username} ) # Add the show to the blacklist. blacklist.add_items(data) ui.notifications.message('Success!', "Added show '{0}' to blacklist".format(show_name)) except TraktException as error: ui.notifications.error('Error!', "Unable to add show '{0}' to blacklist. Check logs.".format(show_name)) log.warning("Error while adding show '{name}' to trakt blacklist: {error}", {'name': show_name, 'error': error}) except Exception as error: log.exception('Error trying to add show to blacklist, error: {error}', {'error': error})
def fetch_popular_shows(self, trakt_list=None): """Get a list of popular shows from different Trakt lists based on a provided trakt_list. :param page_url: the page url opened to the base api url, for retreiving a specific list :param trakt_list: a description of the trakt list :return: A list of RecommendedShow objects, an empty list of none returned :throw: ``Exception`` if an Exception is thrown not handled by the libtrats exceptions """ trending_shows = [] removed_from_medusa = [] try: not_liked_show = '' library_shows = sync.get_watched('shows', extended='noseasons') + sync.get_collection('shows', extended='full') medusa_shows = [show.indexerid for show in app.showList if show.indexerid] removed_from_medusa = [lshow.tvdb for lshow in library_shows if lshow.tvdb not in medusa_shows] if app.TRAKT_BLACKLIST_NAME: trakt_user = get_trakt_user() not_liked_show = trakt_user.get_list(app.TRAKT_BLACKLIST_NAME) or [] else: log.debug('Trakt blacklist name is empty') limit = None if trakt_list not in ['recommended', 'newshow', 'newseason']: limit = 100 + len(not_liked_show) # Get the trakt list shows = get_trakt_show_collection(trakt_list, limit) # Trigger a cache cleanup missing_posters.clean() for show in shows: try: # If there isn't a tvdb id available skip it. We can't add it anyway. if show.tvdb is None: continue if (not_liked_show and show.tvdb in (s.tvdb for s in not_liked_show if s.media_type == 'shows')): continue trending_shows.append(self._create_recommended_show( storage_key=show.trakt, show=show )) except MultipleShowObjectsException: continue # Update the dogpile index. This will allow us to retrieve all stored dogpile shows from the dbm. blacklist = app.TRAKT_BLACKLIST_NAME not in '' except Exception as error: log.exception('Could not connect to Trakt service: {0}', error) raise return blacklist, trending_shows, removed_from_medusa
def test_notify(blacklist_name=None): """Send a test notification to trakt with the given authentication info and returns a boolean. api: The api string to use username: The username to use blacklist_name: slug of trakt list used to hide not interested show Returns: True if the request succeeded, False otherwise """ try: trakt_user = get_trakt_user() if blacklist_name and blacklist_name is not None: trakt_lists = trakt_user.lists found = False for trakt_list in trakt_lists: if trakt_list.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, RequestException) as error: log.warning('Unable to test TRAKT: {error!r}', {'error': error}) return 'Test notice failed to Trakt: {0!r}'.format(error)
def fetch_popular_shows(self, trakt_list=None): """Get a list of popular shows from different Trakt lists based on a provided trakt_list. :param page_url: the page url opened to the base api url, for retreiving a specific list :param trakt_list: a description of the trakt list :return: A list of RecommendedShow objects, an empty list of none returned :throw: ``Exception`` if an Exception is thrown not handled by the libtrats exceptions """ recommended_shows = [] try: not_liked_show = '' removed_from_medusa = self.get_removed_from_medusa() if app.TRAKT_BLACKLIST_NAME: trakt_user = get_trakt_user() not_liked_show = trakt_user.get_list(app.TRAKT_BLACKLIST_NAME) or [] else: log.debug('Trakt blacklist name is empty') limit = None if trakt_list not in ['recommended', 'newshow', 'newseason']: limit = 100 + len(not_liked_show) # Get the trakt list shows = get_trakt_show_collection(trakt_list, limit) # Trigger a cache cleanup missing_posters.clean() for show in shows: try: # If there isn't a tvdb id available skip it. We can't add it anyway. if show.tvdb is None: continue if (not_liked_show and show.tvdb in (s.tvdb for s in not_liked_show if s.media_type == 'shows')): continue recommended_show = self._create_recommended_show(show, subcat=trakt_list) if recommended_show: recommended_show.save_to_db() recommended_shows.append(recommended_show) except MultipleShowObjectsException: continue # # Update the dogpile index. This will allow us to retrieve all stored dogpile shows from the dbm. # update_recommended_series_cache_index('trakt', [binary_type(s.series_id) for s in trending_shows]) blacklist = app.TRAKT_BLACKLIST_NAME not in '' except ForbiddenException as error: log.warning( 'Trying to connect to trakt.tv but it seems you are not authenticated. error: {error}', {'error': error} ) raise except Exception as error: log.exception('Could not connect to Trakt service: {0}', error) return blacklist, recommended_shows, removed_from_medusa
def _get_show_watchlist(self): """Get shows watchlist.""" user = get_trakt_user() return user.watchlist_shows