Example #1
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
                })
Example #2
0
    def remove_episode_watchlist(self):
        """Remove episode from Trakt watchlist."""
        if not (app.TRAKT_SYNC_WATCHLIST and app.USE_TRAKT):
            return

        main_db_con = db.DBConnection()
        statuses = [DOWNLOADED, ARCHIVED]
        sql_selection = 'SELECT s.indexer, s.startyear, s.indexer_id, s.show_name, e.season, e.episode ' \
                        'FROM tv_episodes AS e, tv_shows AS s ' \
                        'WHERE e.indexer = s.indexer ' \
                        'AND s.indexer_id = e.showid AND e.status in ({0})'.format(','.join(['?'] * len(statuses)))

        sql_result = main_db_con.select(sql_selection, statuses)

        if not sql_result:
            return

        episodes = []
        shows = {}
        for cur_episode in sql_result:
            # Check if TRAKT supports that indexer
            if not get_trakt_indexer(cur_episode['indexer']):
                continue

            show_id = cur_episode['indexer'], cur_episode['indexer_id']
            episode = cur_episode['season'], cur_episode['episode']

            if show_id not in shows:
                shows[show_id] = []

            shows[show_id].append(episode)

        media_object_shows = []
        for show_id in shows:
            episodes = []
            show_obj = Show.find_by_id(app.showList, show_id[0], show_id[1])
            for season, episode in shows[show_id]:
                if not self._check_list(indexer=show_obj.indexer,
                                        indexer_id=show_obj.series_id,
                                        season=season,
                                        episode=episode,
                                        list_type='Collection'):
                    continue

                log.info("Removing episode '{show}' {ep} from Trakt watchlist",
                         {
                             'show': show_obj.name,
                             'ep': episode_num(season, episode)
                         })
                episodes.append(show_obj.get_episode(season, episode))
            media_object_shows.append(
                create_episode_structure(show_obj, episodes))

        try:
            sync.remove_from_collection({'shows': media_object_shows})
            self._get_episode_watchlist()
        except TraktException as error:
            log.info(
                'Unable to remove episodes from Trakt watchlist. Error: {error!r}',
                {'error': error})
Example #3
0
 def remove_from_library(self):
     """Remove this :class:`TVEpisode` from your library"""
     remove_from_collection(self)
Example #4
0
 def remove_from_library(self):
     """Remove this :class:`TVSeason` from your library."""
     remove_from_collection(self)
Example #5
0
 def remove_from_library(self):
     """Remove this :class:`TVEpisode` from your library"""
     remove_from_collection(self)
Example #6
0
 def remove_from_library(self):
     """Remove this :class:`TVSeason` from your library."""
     remove_from_collection(self)
Example #7
0
    def remove_episode_trakt_collection(self, filter_show=None):
        """Remove episode from trakt collection.

        For episodes that no longer have a media file (location)
        :param filter_show: optional. Only remove episodes from trakt collection for given shows
        """
        if not (app.TRAKT_SYNC_REMOVE and app.TRAKT_SYNC and app.USE_TRAKT):
            return

        params = []
        main_db_con = db.DBConnection()
        statuses = [DOWNLOADED, ARCHIVED]
        sql_selection = 'SELECT s.indexer, s.startyear, s.indexer_id, s.show_name,' \
                        'e.season, e.episode, e.status ' \
                        'FROM tv_episodes AS e, tv_shows AS s WHERE e.indexer = s.indexer AND ' \
                        's.indexer_id = e.showid and e.location = "" ' \
                        'AND e.status in ({0})'.format(','.join(['?'] * len(statuses)))
        if filter_show:
            sql_selection += ' AND s.indexer_id = ? AND e.indexer = ?'
            params = [filter_show.series_id, filter_show.indexer]

        sql_result = main_db_con.select(sql_selection, statuses + params)

        if not sql_result:
            return

        episodes = []
        shows = {}
        for cur_episode in sql_result:
            # Check if TRAKT supports that indexer
            if not get_trakt_indexer(cur_episode['indexer']):
                continue

            show_id = cur_episode['indexer'], cur_episode['indexer_id']
            episode = cur_episode['season'], cur_episode['episode']

            if show_id not in shows:
                shows[show_id] = []

            shows[show_id].append(episode)

        media_object_shows = []
        for show_id in shows:
            episodes = []
            show_obj = Show.find_by_id(app.showList, show_id[0], show_id[1])
            for season, episode in shows[show_id]:
                if not self._check_list(
                    indexer=show_obj.indexer, indexer_id=show_obj.series_id,
                    season=season, episode=episode,
                    list_type='Collection'
                ):
                    continue

                log.info("Removing episode '{show}' {ep} from Trakt collection", {
                    'show': show_obj.name,
                    'ep': episode_num(season, episode)
                })
                episodes.append(show_obj.get_episode(season, episode))
            media_object_shows.append(create_episode_structure(show_obj, episodes))

        try:
            sync.remove_from_collection({'shows': media_object_shows})
            self._get_show_collection()
        except TraktException as error:
            log.info('Unable to remove episodes from Trakt collection. Error: {error!r}', {
                'error': error
            })