Ejemplo n.º 1
0
    def add_show_trakt_library(self, show_obj):
        """Add show to trakt library."""
        if self.find_show(show_obj.indexerid, show_obj.indexer):
            return

        # Check if TRAKT supports that indexer
        if not get_trakt_indexer(show_obj.indexer):
            return

        log.info("Adding show '{show}' to Trakt library", {'show': show_obj.name})

        try:
            result = sync.add_to_collection(create_show_structure(show_obj))
        except TraktException as error:
            log.info("Unable to add show '{show}' to Trakt library. Error: {error!r}", {
                'show': show_obj.name,
                'error': error
            })
            return

        if result and (result.get('added') or result.get('existing')):
            if result['added']['shows']:
                return True

        return False
Ejemplo n.º 2
0
    def add_show_watchlist(self):
        """Add show to Trakt watchlist.

        It will add all shows from Medusa library
        """
        if not (app.TRAKT_SYNC_WATCHLIST and app.USE_TRAKT):
            return

        if not app.showList:
            return

        trakt_show_objects = []
        for show_obj in app.showList:
            if not self._check_list(show_obj=show_obj, list_type='Show'):
                log.info("Adding show '{show}' to Trakt watchlist",
                         {'show': show_obj.name})
                trakt_show_objects.append(create_show_structure(show_obj))

        if trakt_show_objects:
            try:
                sync.add_to_watchlist({'shows': trakt_show_objects})
            except TraktException as error:
                log.info(
                    'Unable to add shows to Trakt watchlist. Error: {error!r}',
                    {'error': error})
            self._get_show_watchlist()
Ejemplo n.º 3
0
    def remove_show_trakt_library(self, show_obj):
        """Remove show from trakt library."""
        if self.find_show(show_obj.indexerid, show_obj.indexer):

            # Check if TRAKT supports that indexer
            if not get_trakt_indexer(show_obj.indexer):
                return

            log.info("Removing '{show}' from Trakt library", {'show': show_obj.name})

            # Remove all episodes from the Trakt collection for this show
            try:
                self.remove_episode_trakt_collection(filter_show=show_obj)
            except TraktException as error:
                log.info("Unable to remove all episodes from show '{show}' from Trakt library. Error: {error!r}", {
                    'show': show_obj.name,
                    'error': error
                })

            try:
                sync.remove_from_collection(create_show_structure(show_obj))
            except TraktException as error:
                log.info("Unable to remove show '{show}' from Trakt library. Error: {error!r}", {
                    'show': show_obj.name,
                    'error': error
                })
Ejemplo n.º 4
0
    def update_watchlist_show(show_obj, remove=False):
        """Use Trakt sync/watchlist to updata a show."""
        trakt_media_object = {'shows': [create_show_structure(show_obj)]}

        try:
            if remove:
                result = sync.remove_from_watchlist(trakt_media_object)
            else:
                result = sync.add_to_watchlist(trakt_media_object)
        except (TraktException, RequestException) as error:
            log.warning('Unable to update Trakt: {error!r}', {'error': error})
            return False

        if result and (result.get('added') or result.get('existing')):
            if result['added']['shows']:
                return True

        return False