def update_tracks(media_id, track_file): try: tags = File(track_file, None, True) artist_str = " / ".join(tags["artist"]) update_track(media_id, artist_str) except Exception, e: PlexLog.error(e)
def search(self, results, media, lang, manual): PlexLog.debug("=================== Search Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) movie = get_movie(media) if movie is None: return title = movie.get("title") if title is None: PlexLog.error("Missing or invalid title: %s" % str(movie)) return aired = convert_date(movie.get("aired")) year = aired.year if aired is not None else 0 # Plex throws exception that have "/" in ID mid = create_id(title, year) result = MetadataSearchResult(id=mid, name=title, year=year, lang=lang, score=100) results.Append(result) PlexLog.debug("=================== Search end ===================")
def update(self, metadata, media, lang, force): PlexLog.debug("=================== Update Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] if not server: PlexLog.error("Missing server!") return show = request_json(urljoin(server, "show"), as_show(media)) if show is None: return set_show(metadata, media, show) season_summary = show.get("season_summary", {}) for season in media.seasons: season_id = media.seasons[season].id summary = season_summary.get(season) if summary is not None: update_season_summary(season_id, summary) for episode in media.seasons[season].episodes: episode_metadata = metadata.seasons[season].episodes[episode] model = request_json(urljoin(server, "episode"), as_episode(media, season, episode)) set_episode(episode_metadata, model) set_episode_cover(episode_metadata, media, season, episode) PlexLog.debug("=================== Update end ===================")
def update_show(media_id, original_title, tagline): if original_title is None and tagline is None: PlexLog.warn("Missing original_title and tagline!") return query = {} if tagline is not None: query["tagline.value"] = tagline if original_title is not None: query["originalTitle.value"] = original_title update_put(media_id, 2, query)
def get_episode_json(media, season, episode): path = get_show_file(media) season_dir = dirname(path) name = guess_name(path) file = episode_file(name, season, episode, "json") file_path = join(season_dir, file) if not exists(file_path): PlexLog.error("No JSON for %s" % file_path) return None string = Core.storage.load(file_path) return JSON.ObjectFromString(string)
def update(self, metadata, media, lang, force): PlexLog.debug("=================== Update Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] if not server: PlexLog.error("Missing server!") return album = request_json(urljoin(server, "album"), as_album(media)) if album is None: return set_album(metadata, media, album) PlexLog.debug("=================== Update end ===================")
def update(self, metadata, media, lang, force): PlexLog.debug("=================== Update Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) album = get_album(media) if album is None: return set_album(metadata, media, album) PlexLog.debug("=================== Update end ===================")
def update_put(media_id, update_type, parameters): token = Prefs["Token"] if not token: PlexLog.warn("Missing token!") return localhost = "http://127.0.0.1:32400" page_url = localhost + "/library/metadata/" + media_id xml_element = XML.ElementFromURL(page_url) container = xml_element.xpath("//MediaContainer")[0] section = String.Unquote(container.get("librarySectionID").encode("utf-8")) query = { "type": update_type, "id": media_id, # Movie Type 1 "X-Plex-Token": token } query.update(parameters) request_url = localhost + "/library/sections/" + section + "/all?" response = requests.put(request_url, params=query) if not response.ok: PlexLog.error("Fail to put update (%d)" % response.status_code)
def request_json(url, json): PlexLog.debug("Request JSON %s" % str(request_json)) response = requests.post(url, json=json) status_code = response.status_code if status_code != 200: PlexLog.error("HTTP response (%d)" % status_code) return None try: response_json = response.json() except ValueError: PlexLog.error("Invalid JSON response") return None PlexLog.debug("Response JSON: %s" % str(response_json)) return response_json
def search(self, results, media, lang, manual): PlexLog.debug("=================== Search Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] if not server: PlexLog.error("Missing server!") return album = request_json(urljoin(server, "album"), as_album(media)) if album is None: return result = MetadataSearchResult(id=media.id, name=media.title, lang=lang, year=None, score=100) results.Append(result) PlexLog.debug("=================== Search end ===================")
def search(self, results, media, lang, manual): PlexLog.debug("=================== Search Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) album = get_album(media) if album is None: return result = MetadataSearchResult(id=media.id, name=media.title, lang=lang, year=None, score=100) results.Append(result) PlexLog.debug("=================== Search end ===================")
def update(self, metadata, media, lang, force): PlexLog.debug("=================== Update Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) show = get_show_json(media) if show is None: return set_show(metadata, show) for season in media.seasons: for episode in media.seasons[season].episodes: episode_metadata = metadata.seasons[season].episodes[episode] model = get_episode_json(media, season, episode) if model is not None: set_episode(episode_metadata, model) set_episode_cover(episode_metadata, media, season, episode) PlexLog.debug("=================== Update end ===================")
def update(self, metadata, media, lang, force): PlexLog.debug("=================== Update Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) show = get_show(media) if show is None: return set_show(metadata, media, show) season_summary = show.get("season_summary", {}) for season in media.seasons: season_id = media.seasons[season].id summary = season_summary.get(int(season)) if summary is not None: update_season_summary(season_id, summary) for episode in media.seasons[season].episodes: episode_metadata = metadata.seasons[season].episodes[episode] model = get_episode(media, season, episode) set_episode(episode_metadata, model) set_episode_cover(episode_metadata, media, season, episode) PlexLog.debug("=================== Update end ===================")
def set_metadata_posters(metadata, posterUrls): if posterUrls is None: return valid_names = list() i = 0 PlexLog.info('Attempting to get new posters') for posterUrl in posterUrls: if posterUrl not in metadata.posters: valid_names.append(posterUrl) try: metadata.posters[posterUrl] = Proxy.Preview( HTTP.Request(posterUrl).content, sort_order=i + 1) PlexLog.info('New poster added: %s' % posterUrl) except: PlexLog.error('New poster error: %s' % posterUrl) pass metadata.posters.validate_keys(valid_names)
def search(self, results, media, lang, manual): PlexLog.debug("=================== Search Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] authKey = Prefs["AuthKey"] if not server: PlexLog.error("Missing server!") return requestUrl = urljoin(server, "movie") if authKey: requestUrl = requestUrl + "?AuthKey=" + authKey PlexLog.debug("Requesting URL: %s" % requestUrl) movie = request_json(requestUrl, as_movie(media)) if movie is None: return title = movie.get("title") if title is None: PlexLog.error("Missing or invalid title: %s" % str(movie)) return aired = convert_date(movie.get("aired")) year = aired.year if aired is not None else 0 # Plex throws exception that have "/" in ID mid = create_id(title, year) result = MetadataSearchResult(id=mid, name=title, year=year, lang=lang, score=100) results.Append(result) PlexLog.debug("=================== Search end ===================")
def update(self, metadata, media, lang, force): PlexLog.debug("=================== Update Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] authKey = Prefs["AuthKey"] if not server: PlexLog.error("Missing server!") return requestUrl = urljoin(server, "album") if authKey: requestUrl = requestUrl + "?AuthKey=" + authKey PlexLog.debug("Requesting URL: %s" % requestUrl) album = request_json(requestUrl, as_album(media)) if album is None: return set_album(metadata, media, album) PlexLog.debug("=================== Update end ===================")
def update_season_summary(media_id, summary): if summary is None: PlexLog.warn("Missing summary!") return query = {"summary.value": summary} update_put(media_id, 3, query)
def search(self, results, media, lang, manual): PlexLog.debug("=================== Search Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] if not server: PlexLog.error("Missing server!") return show = request_json(urljoin(server, "show"), as_show(media)) if show is None: return title = show.get("title") if title is None: PlexLog.error("Missing or invalid title: %s" % str(show)) return aired = convert_date(show.get("aired")) year = aired.year if aired is not None else 0 # Plex throws exception that have "/" in ID mid = create_id(title, year) result = MetadataSearchResult(id=mid, name=title, year=year, lang=lang, score=100) results.Append(result) PlexLog.debug("=================== Search end ===================")
def update_track(media_id, artist): if artist is None: PlexLog.warn("Missing artist!") query = {"originalTitle.value": artist} update_put(media_id, 10, query)
def search(self, results, media, lang, manual): PlexLog.debug("=================== Search Start ===================") PlexLog.debug("%s (%s)" % (self.name, self.ver)) PlexLog.debug("Plex version: %s" % Platform.ServerVersion) server = Prefs["Server"] authKey = Prefs["AuthKey"] if not server: PlexLog.error("Missing server!") return requestUrl = urljoin(server, "artist") if authKey: requestUrl = requestUrl + "?AuthKey=" + authKey PlexLog.debug("Requesting URL: %s" % requestUrl) artist = request_json(requestUrl, as_artist(media)) if artist is None: return result = MetadataSearchResult(id=media.id, name=media.title, lang=lang, year=None, score=100) results.Append(result) PlexLog.debug("=================== Search end ===================")