def from_event(cls, info):
        account_key = try_convert(info.get('account_key'), int)
        rating_key = info.get('rating_key')

        if account_key is None or rating_key is None:
            log.warn('Invalid action format: %s', info)
            return None

        if account_key != 1:
            log.debug('Ignoring action from shared account')
            return None

        if WatchSession.is_active(rating_key, lambda ws: not ws.update_required):
            log.debug('Ignoring action, item is currently being watched')
            return False

        metadata = Metadata.get(rating_key)

        if not metadata:
            log.debug('Ignoring action, unable to retrieve metadata')
            return False

        section = metadata.section.title.lower()

        f_allow, _ = get_filter('filter_sections')

        if f_allow is not None and section not in f_allow:
            log.debug('Ignoring action, section has been filtered')
            return False

        guid = Guid.parse(metadata.guid)

        request = {}

        if type(metadata) is Movie:
            request = cls.from_movie(metadata, guid)
        elif type(metadata) is Season:
            request = cls.from_season(metadata, guid)
        elif type(metadata) is Episode:
            request = cls.from_episode(metadata, guid)
        else:
            log.warn('Unsupported metadata type: %r', metadata)
            return None

        log.debug('request: %r', request)

        return request
示例#2
0
    def watch(self, key, p_items, t_item):
        if type(p_items) is not list:
            p_items = [p_items]

        # Ignore if trakt movie is already watched
        if t_item and t_item.is_watched:
            return True

        # Ignore if none of the plex items are watched
        if all([not x.seen for x in p_items]):
            return True

        # Ignore if we are currently watching this item
        if WatchSession.is_active(p_items[0].rating_key):
            log.trace("[P #%s] ignored - item is currently being watched", p_items[0].rating_key)
            return True

        # Build item which can be sent to trakt
        item = ActionHelper.plex.to_trakt(key, p_items[0])

        if not item:
            log.warn('watch() - Ignored for unmatched media "%s" [%s]', p_items[0].title, key)
            return True

        # Check action against history
        history = ActionManager.history.get(p_items[0].rating_key, {})

        if not ActionManager.valid_action("add", history):
            log.debug(
                'watch() - Invalid action for "%s" [%s] (already scrobbled or duplicate action)', p_items[0].title, key
            )
            return True

        # Mark item as added in `pts.action_manager`
        ActionManager.update_history(p_items[0].rating_key, "add", "add")

        # Set "watched_at" parameter (if available)
        watched_at = self.get_datetime(p_items[0], "last_viewed_at")

        if watched_at:
            item["watched_at"] = watched_at

        # Store item in "watched" collection
        self.store("watched", item)

        return True