Ejemplo n.º 1
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
Ejemplo n.º 2
0
    def watch(self, p_items, t_item):
        if type(p_items) is not list:
            p_items = [p_items]

        if not t_item.is_watched:
            return True

        for p_item in p_items:
            # Ignore already seen movies
            if p_item.seen:
                continue

            # Scrobble item
            Plex['library'].scrobble(p_item.rating_key)

            # Mark item as added in `pts.action_manager`
            ActionManager.update_history(p_item.rating_key, 'add', 'add')

        return True