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 if not self.valid_trakt_id(media_id): logger.error(f"Ignoring invalid id: '{media_id}'") 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
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()
def history(self, m, device=False, account=False): try: history = m.history() except Unauthorized as e: logger.debug(f"No permission to access play history: {e}") return for h in history: if device: h.device = self.system_device(h.deviceID) if account: h.account = self.system_account(h.accountID) yield h
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)
def sync(self, rating_key: int): media = self.find_media(rating_key) logger.debug(f"Found: {media}")
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")