Esempio n. 1
0
def fetch_shows():
    result = {}

    for guid, shows in Library.all(types=['show']).items():
        show = shows[0]

        episodes = Library.episodes(show.rating_key, show)

        result[guid] = {'show': show, 'episodes': episodes}

    return result
Esempio n. 2
0
def fetch_shows():
    result = {}

    for guid, shows in Library.all(types=['show']).items():
        show = shows[0]

        episodes = Library.episodes(show.rating_key, show)

        result[guid] = {
            'show': show,
            'episodes': episodes
        }

    return result
Esempio n. 3
0
def fetch_movies():
    result = {}

    for guid, movies in Library.all(types=['movie']).items():
        movie = movies[0]

        result[guid] = {'movie': movie}

    return result
Esempio n. 4
0
def fetch_movies():
    result = {}

    for guid, movies in Library.all(types=['movie']).items():
        movie = movies[0]

        result[guid] = {
            'movie': movie
        }

    return result
Esempio n. 5
0
    def run(self, section=None):
        self.check_stopping()

        enabled_funcs = self.get_enabled_functions()
        if not enabled_funcs:
            log.info('There are no functions enabled, skipping pull.show')
            return True

        p_shows = self.plex.library('show')
        self.save('last_library', p_shows, source='plex')

        if p_shows is None:
            log.warn('Unable to retrieve shows library from plex')
            return False

        # Fetch library, and only get ratings and collection if enabled
        t_shows, t_shows_table = self.trakt.merged('shows', ratings='ratings' in enabled_funcs, collected=True)
        self.save('last_library', t_shows_table, source='trakt')

        if t_shows is None:
            log.warn('Unable to construct merged library from trakt')
            return False

        self.emit('started', len(t_shows_table))

        for x, (key, t_show) in enumerate(t_shows_table.iteritems()):
            self.check_stopping()
            self.emit('progress', x + 1)

            if key is None or key not in p_shows or not t_show.seasons:
                continue

            log.debug('Processing "%s" [%s]', t_show.title, key)

            t_show.is_local = True

            # Trigger show functions
            self.trigger(enabled_funcs, p_shows=p_shows[key], t_show=t_show)

            # Run through each matched show and run episode functions
            for p_show in p_shows[key]:
                self.child('season').run(
                    p_seasons=Library.episodes(p_show.rating_key, p_show, flat=False),
                    t_seasons=t_show.seasons if t_show else {}
                )

        self.emit('finished')
        self.check_stopping()

        # Trigger plex missing show/episode discovery
        self.discover_missing(t_shows)

        log.info('Finished pulling shows from trakt')
        return True
Esempio n. 6
0
    def run(self, section=None, artifacts=None):
        self.reset(artifacts)
        self.check_stopping()

        enabled_funcs = self.get_enabled_functions()
        if not enabled_funcs:
            log.info('There are no functions enabled, skipping push.show')
            return True

        p_shows = self.plex.library('show', section)
        if not p_shows:
            # No items found, no need to continue
            return True

        # Fetch library, and only get ratings and collection if enabled
        t_shows, t_shows_table = self.trakt.merged(
            'shows',
            ratings='ratings' in enabled_funcs,
            collected='collected' in enabled_funcs
        )

        if t_shows_table is None:
            log.warn('Unable to construct merged library from trakt')
            return False

        self.emit('started', len(p_shows))

        for x, (key, p_shows) in enumerate(p_shows.iteritems()):
            self.check_stopping()
            self.emit('progress', x + 1)

            t_show = t_shows_table.get(key)

            log.debug('Processing "%s" [%s]', p_shows[0].title if p_shows else None, key)

            # TODO check result
            self.trigger(enabled_funcs, key=key, p_shows=p_shows, t_show=t_show)

            show = None
            show_artifacts = {
                'collected': [],
                'watched': [],
                'ratings': []
            }

            for p_show in p_shows:
                if not show:
                    # Build data from plex show
                    data = ActionHelper.plex.to_trakt(key, p_show)

                    if data:
                        # Valid show, use data
                        show = data
                    else:
                        log.warn('Ignored unmatched show "%s" [%s]', p_show.title if p_show else None, key)
                        continue

                # Run season task
                self.child('season').run(
                    p_seasons=Library.episodes(p_show.rating_key, p_show, flat=False),
                    t_seasons=t_show.seasons if t_show else {},
                    artifacts=artifacts
                )

                # Store season artifacts
                show_artifacts['collected'].append(
                    self.child('season').artifacts.pop('collected', [])
                )

                show_artifacts['watched'].append(
                    self.child('season').artifacts.pop('watched', [])
                )

                show_artifacts['ratings'].append(
                    self.child('season').artifacts.pop('ratings', [])
                )

            if not show:
                log.warn('Unable to retrieve show details, ignoring "%s" [%s]', p_show.title if p_show else None, key)
                continue

            # Merge show artifacts
            for k, v in show_artifacts.iteritems():
                result = []

                for seasons in v:
                    result = self.merge_artifacts(result, seasons)

                show_artifacts[k] = result

            # Store merged artifacts
            self.store_seasons('collected', show, seasons=show_artifacts.get('collected'))
            self.store_seasons('watched', show, seasons=show_artifacts.get('watched'))

            show_rating = self.rate(key, p_shows, t_show, artifact='', include_metadata=False)

            self.store_seasons('ratings', merge(
                # Include show rating
                show_rating,
                show
            ), seasons=show_artifacts.get('ratings'))

        self.emit('finished')
        self.check_stopping()

        #
        # Push changes to trakt
        #
        self.add('sync/collection', shows=self.retrieve('collected'))
        self.add('sync/history', shows=self.retrieve('watched'))
        self.add('sync/ratings', shows=self.retrieve('ratings'))

        self.remove('sync/collection', shows=self.retrieve('missing.shows'))

        self.save('last_artifacts', self.artifacts.store)

        log.info('Finished pushing shows to trakt')
        return True
Esempio n. 7
0
    def library(cls, types=None, keys=None, titles=None):
        # Default to 'titles' filter preference
        if titles is None:
            titles, _ = get_filter('filter_sections')

        return Library.all(types, keys, titles)