示例#1
0
    def send(self, action, **kwargs):
        # TODO maybe this can be handled in trakt.py somehow?
        path = action[:action.rfind('/')]
        action = action[action.rfind('/') + 1:]

        response = Trakt[path][action](**kwargs)

        if response is None:
            # Request failed (rejected unmatched media, etc..)
            return

        # Log successful items
        if 'rated' in response:
            rated = response.get('rated')
            unrated = response.get('unrated')

            log.info(
                '(%s) Rated %s item%s and un-rated %s item%s',
                action,
                rated, plural(rated),
                unrated, plural(unrated)
            )
        elif 'message' in response:
            log.info('(%s) %s', action, response['message'])
        else:
            self.log_artifact(action, 'Inserted', response.get('inserted'))

        # Log skipped items, if there were any
        skipped = response.get('skipped', 0)

        if skipped > 0:
            self.log_artifact(action, 'Skipped', skipped, level='warn')
def create_active_item(oc):
    task, handler = SyncManager.get_current()
    if not task:
        return

    # Format values
    remaining = format_remaining(task.statistics.seconds_remaining)
    progress = format_percentage(task.statistics.progress)

    # Title
    title = '%s - Status' % normalize(handler.title)

    if progress:
        title += ' (%s)' % progress

    # Summary
    summary = task.statistics.message or 'Working'

    if remaining:
        summary += ', ~%s second%s remaining' % (remaining, plural(remaining))

    # Create items
    oc.add(DirectoryObject(
        key=Callback(SyncMenu, refresh=timestamp()),
        title=pad_title(title),
        summary=summary + ' (click to refresh)'
    ))

    oc.add(DirectoryObject(
        key=Callback(Cancel),
        title=pad_title('%s - Cancel' % normalize(handler.title))
    ))
示例#3
0
def create_active_item(oc):
    task, handler = SyncManager.get_current()
    if not task:
        return

    # Format values
    remaining = format_remaining(task.statistics.seconds_remaining)
    progress = format_percentage(task.statistics.progress)

    # Title
    title = '%s - Status' % handler.title

    if progress:
        title += ' (%s)' % progress

    # Summary
    summary = task.statistics.message or 'Working'

    if remaining:
        summary += ', ~%s second%s remaining' % (remaining, plural(remaining))

    # Create items
    oc.add(
        DirectoryObject(key=Callback(SyncMenu, refresh=timestamp()),
                        title=pad_title(title),
                        summary=summary + ' (click to refresh)'))

    oc.add(
        DirectoryObject(key=Callback(Cancel),
                        title=pad_title('%s - Cancel' % handler.title)))
示例#4
0
    def discover_missing(self, t_shows):
        # Ensure collection cleaning is enabled
        if not Prefs['sync_clean_collection']:
            return

        log.info('Searching for shows/episodes that are missing from plex')

        # Find collected shows that are missing from Plex
        t_collection_missing = self.get_missing(t_shows, is_collected=False)

        # Discover entire shows missing
        num_shows = 0
        for key, t_show in t_collection_missing.items():
            # Ignore show if there are no collected episodes on trakt
            if all([not e.is_collected for (_, e) in t_show.episodes.items()]):
                continue

            self.store('missing.shows', t_show.to_info())
            num_shows = num_shows + 1

        # Discover episodes missing
        num_episodes = 0
        for key, t_show in t_shows.items():
            if t_show.pk in t_collection_missing:
                continue

            t_episodes_missing = self.get_missing(t_show.episodes)

            if not t_episodes_missing:
                continue

            self.store_episodes(
                'missing.episodes', t_show.to_info(),
                episodes=[x.to_info() for x in t_episodes_missing.itervalues()]
            )

            num_episodes = num_episodes + len(t_episodes_missing)

        log.info(
            'Found %s show%s and %s episode%s missing from plex',
            num_shows, plural(num_shows),
            num_episodes, plural(num_episodes)
        )
示例#5
0
    def discover_missing(self, t_shows):
        # Ensure collection cleaning is enabled
        if not Prefs['sync_clean_collection']:
            return

        log.info('Searching for shows/episodes that are missing from plex')

        # Find collected shows that are missing from Plex
        t_collection_missing = self.get_missing(t_shows, is_collected=False)

        # Discover entire shows missing
        num_shows = 0
        for key, t_show in t_collection_missing.items():
            # Ignore show if there are no collected episodes on trakt
            if all([not e.is_collected for (_, e) in t_show.episodes.items()]):
                continue

            self.store('missing.shows', t_show.to_info())
            num_shows = num_shows + 1

        # Discover episodes missing
        num_episodes = 0
        for key, t_show in t_shows.items():
            if t_show.pk in t_collection_missing:
                continue

            t_episodes_missing = self.get_missing(t_show.episodes)

            if not t_episodes_missing:
                continue

            self.store_episodes('missing.episodes',
                                t_show.to_info(),
                                episodes=[
                                    x.to_info()
                                    for x in t_episodes_missing.itervalues()
                                ])

            num_episodes = num_episodes + len(t_episodes_missing)

        log.info('Found %s show%s and %s episode%s missing from plex',
                 num_shows, plural(num_shows), num_episodes,
                 plural(num_episodes))
示例#6
0
    def log_artifact(action, label, count, level='info'):
        message = '(%s) %s %s item%s' % (
            action, label, count,
            plural(count)
        )

        if level == 'info':
            return log.info(message)
        elif level == 'warn':
            return log.warn(message)

        raise ValueError('Unknown level specified')
示例#7
0
    def send(self, action, data):
        response = Trakt.request(action, data, authenticate=True)

        # Log successful items
        if 'rated' in response:
            rated = response.get('rated')
            unrated = response.get('unrated')

            log.info(
                '(%s) Rated %s item%s and un-rated %s item%s',
                action,
                rated, plural(rated),
                unrated, plural(unrated)
            )
        elif 'message' in response:
            log.info('(%s) %s', action, response['message'])
        else:
            self.log_artifact(action, 'Inserted', response.get('inserted'))

        # Log skipped items, if there were any
        skipped = response.get('skipped', 0)

        if skipped > 0:
            self.log_artifact(action, 'Skipped', skipped, level='warn')
示例#8
0
    def discover_missing(self, t_movies):
        # Ensure collection cleaning is enabled
        if not Prefs['sync_clean_collection']:
            return

        log.info('Searching for movies that are missing from plex')

        # Find collected movies that are missing from Plex
        t_collection_missing = self.get_missing(t_movies)

        num_movies = 0
        for key, t_movie in t_collection_missing.items():
            log.debug('Unable to find "%s" [%s] in library', t_movie.title, key)
            self.store('missing.movies', t_movie.to_info())
            num_movies = num_movies + 1

        log.info('Found %s movie%s missing from plex', num_movies, plural(num_movies))
示例#9
0
    def discover_missing(self, t_movies):
        # Ensure collection cleaning is enabled
        if not Prefs['sync_clean_collection']:
            return

        log.info('Searching for movies that are missing from plex')

        # Find collected movies that are missing from Plex
        t_collection_missing = self.get_missing(t_movies)

        num_movies = 0
        for key, t_movie in t_collection_missing.items():
            log.debug('Unable to find "%s" [%s] in library', t_movie.title,
                      key)
            self.store('missing.movies', t_movie.to_info())
            num_movies = num_movies + 1

        log.info('Found %s movie%s missing from plex', num_movies,
                 plural(num_movies))
    def start(cls, blocking=False):
        if not blocking:
            spawn(cls.start, blocking=True)
            return

        cls.log = Logger(cls.tag)
        cls.filter_available()

        # Test methods until an available method is found
        for weight, method in cls.available:
            if weight is None:
                cls.start_method(method)
            elif method.test():
                cls.start_method(method)
                break
            else:
                cls.log.info("method '%s' not available" % method.name)

        cls.log.info(
            'Finished starting %s method%s: %s',
            len(cls.enabled), plural(cls.enabled),
            ', '.join([("'%s'" % m.name) for m in cls.enabled])
        )
    def start(cls, blocking=False):
        if not blocking:
            spawn(cls.start, blocking=True)
            return

        cls.filter_available()

        # Test methods until an available method is found
        for weight, method in cls.available:
            if weight is None:
                cls.start_method(method)
            elif method.test():
                cls.start_method(method)
                break
            else:
                log.info("method '%s' not available" % method.name, tag=cls.tag)

        log.info(
            'Finished starting %s method%s: %s',
            len(cls.enabled), plural(cls.enabled),
            ', '.join([("'%s'" % m.name) for m in cls.enabled]),

            tag=cls.tag
        )