Example #1
0
    def add_episode_trakt_collection(self):
        """Add all existing episodes to Trakt collections.

        For episodes that have a media file (location)
        """
        if not(app.TRAKT_SYNC 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}) AND e.location <> ''".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("Adding episode '{show}' {ep} to 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.add_to_collection({'shows': media_object_shows})
            self._get_show_collection()
        except TraktException as error:
            log.info('Unable to add episodes to Trakt collection. Error: {error!r}', {'error': error})
Example #2
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
Example #3
0
    def update_library(ep_obj):
        """Send a request to trakt indicating that the given episode is part of our library.

        ep_obj: The Episode object to add to trakt
        """
        # Check if TRAKT supports that indexer
        if not get_trakt_indexer(ep_obj.series.indexer):
            return

        if app.USE_TRAKT:
            try:
                # URL parameters
                title = get_title_without_year(ep_obj.series.name,
                                               ep_obj.series.start_year)
                data = {
                    'shows': [{
                        'title': title,
                        'year': ep_obj.series.start_year,
                        'ids': {},
                    }]
                }

                data['shows'][0]['ids'][get_trakt_indexer(
                    ep_obj.series.indexer)] = ep_obj.series.indexerid

                # Add Season and Episode + Related Episodes
                data['shows'][0]['seasons'] = [{
                    'number': ep_obj.season,
                    'episodes': []
                }]

                for rel_ep_obj in [ep_obj] + ep_obj.related_episodes:
                    data['shows'][0]['seasons'][0]['episodes'].append(
                        {'number': rel_ep_obj.episode})

                if app.TRAKT_SYNC_WATCHLIST:
                    if app.TRAKT_REMOVE_SERIESLIST:
                        sync.remove_from_watchlist(data)

                # update library
                sync.add_to_collection(data)
            except (TraktException, RequestException) as error:
                log.warning('Unable to update Trakt: {error!r}',
                            {'error': error})
Example #4
0
 def add_to_library(self):
     """Add this :class:`TVEpisode` to your Trakt.tv library"""
     add_to_collection(self)
Example #5
0
 def add_to_library(self):
     """Add this :class:`TVSeason` to your library."""
     add_to_collection(self)
Example #6
0
 def add_to_library(self):
     """Add this :class:`TVEpisode` to your Trakt.tv library"""
     add_to_collection(self)
Example #7
0
 def add_to_library(self):
     """Add this :class:`TVSeason` to your library."""
     add_to_collection(self)
Example #8
0
 def add_to_library(self):
     """Add this :class:`Movie` to your library."""
     add_to_collection(self)
Example #9
0
 def add_to_library(self):
     """Add this :class:`TVShow` to your library."""
     return add_to_collection(self)
Example #10
0
 def add_to_library(self):
     """Add this :class:`Movie` to your library."""
     add_to_collection(self)