def save_subtitles_to_metadata(videos, subtitles): for video, video_subtitles in subtitles.items(): mediaPart = videos[video] for subtitle in video_subtitles: content = subtitle.get_modified_content(debug=config.debug_mods) if not isinstance(mediaPart, Framework.api.agentkit.MediaPart): # we're being handed a Plex.py model instance here, not an internal PMS MediaPart object. # get the correct one mp = PMSMediaProxy(video.id).get_part(mediaPart.id) else: mp = mediaPart pm = Proxy.Media(content, ext="srt", forced="1" if subtitle.language.forced else None) new_key = "subzero_md" + ("_forced" if subtitle.language.forced else "") lang = Locale.Language.Match(subtitle.language.alpha2) for key, proxy in getattr(mp.subtitles[lang], "_proxies").iteritems(): if not proxy or not len(proxy) >= 5: Log.Debug("Can't parse metadata: %s" % repr(proxy)) continue if proxy[0] == "Media": if not key.startswith("subzero_"): if key == "subzero": Log.Debug("Removing legacy metadata subtitle for %s", lang) del mp.subtitles[lang][key] Log.Debug("Existing metadata subtitle for %s: %s", lang, key) Log.Debug("Adding metadata sub for %s: %s", lang, subtitle) mp.subtitles[lang][new_key] = pm return True
def save_subtitles_to_metadata(videos, subtitles, is_forced=False): for video, video_subtitles in subtitles.items(): mediaPart = videos[video] for subtitle in video_subtitles: content = subtitle.get_modified_content(debug=config.debug_mods) if not isinstance(mediaPart, Framework.api.agentkit.MediaPart): # we're being handed a Plex.py model instance here, not an internal PMS MediaPart object. # get the correct one mp = PMSMediaProxy(video.id).get_part(mediaPart.id) else: mp = mediaPart pm = Proxy.Media(content, ext="srt", forced="1" if is_forced else None) lang = Locale.Language.Match(subtitle.language.alpha2) mp.subtitles[lang].validate_keys({}) mp.subtitles[lang]["subzero"] = pm return True
def save_subtitles_to_metadata(videos, subtitles): for video, video_subtitles in subtitles.items(): mediaPart = videos[video] for subtitle in video_subtitles: content = subtitle.get_modified_content(debug=config.debug_mods) if not isinstance(mediaPart, Framework.api.agentkit.MediaPart): # we're being handed a Plex.py model instance here, not an internal PMS MediaPart object. # get the correct one mp = PMSMediaProxy(video.id).get_part(mediaPart.id) else: mp = mediaPart mp.subtitles[Locale.Language.Match(subtitle.language.alpha2)][subtitle.id] = Proxy.Media(content, ext="srt") return True