Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 def _get_show_collection(self):
     """Get show collection."""
     try:
         self.collection_list = sync.get_collection('shows')
     except TraktException as error:
         log.info('Unable to retrieve shows from Trakt collection. Error: {error!r}', {'error': error})
         return False
     return True
Exemplo n.º 3
0
    def get_removed_from_medusa(self):
        """
        Return an array of shows (tvdb id's) that are still located in the trakt `watched` and `show collection` collections.

        But that are not in medusa's library.
        Library is compared based on the tvdb id's.
        """
        library_shows = sync.get_watched('shows', extended='noseasons') + sync.get_collection('shows', extended='full')
        medusa_shows = [show.externals.get('tvdb_id', show.series_id) for show in app.showList if show.series_id]
        return [lshow.tvdb for lshow in library_shows if lshow.tvdb not in medusa_shows]
Exemplo n.º 4
0
    def find_show(self, indexerid, indexer):
        """Find show in Trakt library."""
        trakt_library = []
        try:
            trakt_library = sync.get_collection('shows')
        except TraktException as error:
            log.info('Unable to retrieve shows from Trakt collection. Error: {error!r}', {'error': error})

        if not trakt_library:
            log.info('No shows found in your Trakt library. Nothing to sync')
            return
        trakt_show = [show for show in trakt_library if
                      get_trakt_indexer(indexer) and int(indexerid) in [int(show.ids['ids'].get(get_trakt_indexer(indexer)))]]

        return trakt_show if trakt_show else None