Example #1
0
    def wait_if_needed(self):
        if not self.last_time:
            self.update()
            return

        wait = self.time_remaining
        if wait:
            logger.debug(f"Sleeping for {wait:.3f} seconds")
            sleep(wait)
        self.update()
Example #2
0
    def search_by_id(self, media_id: str, id_type: str, media_type: str):
        if id_type == "tvdb" and media_type == "movie":
            # Skip invalid search.
            # The Trakt API states that tvdb is only for shows and episodes:
            # https://trakt.docs.apiary.io/#reference/search/id-lookup/get-id-lookup-results
            logger.debug("tvdb does not support movie provider")
            return None

        search = trakt.sync.search_by_id(media_id,
                                         id_type=id_type,
                                         media_type=media_type)
        # look for the first wanted type in the results
        # NOTE: this is not needed, kept around for caution
        for m in search:
            if m.media_type != f"{media_type}s":
                logger.error(
                    f"Internal error, wrong media type: {m.media_type}. Please report this to PlexTraktSync developers"
                )
                continue
            return m

        return None
Example #3
0
    def handle(self, payload):
        logger.debug(f"Handle: {payload}")
        if "rating_key" not in payload:
            logger.debug("Skip, no ratingKey in payload")
            return

        rating_key = int(payload["rating_key"])
        logger.debug(f"RatingKey: {rating_key}")
        if rating_key:
            self.sync(rating_key)
Example #4
0
 def delete_playlist(self, name: str):
     try:
         self.plex.playlist(name).delete()
     except (NotFound, BadRequest):
         logger.debug(f"Playlist '{name}' not found, so it could not be deleted")
Example #5
0
 def sync(self, rating_key: int):
     media = self.find_media(rating_key)
     logger.debug(f"Found: {media}")