def SubtitleColorModMenu(**kwargs): kwargs.pop("randomize") color_mod = SubtitleModifications.get_mod_class("color") oc = SubFolderObjectContainer(title2=kwargs["title"], replace_parent=True) oc.add( DirectoryObject(key=Callback(SubtitleModificationsMenu, randomize=timestamp(), **kwargs), title="< Back to subtitle modification menu")) for color, code in color_mod.colors.iteritems(): mod_ident = SubtitleModifications.get_mod_signature( "color", **{"name": color}) oc.add( DirectoryObject(key=Callback(SubtitleSetMods, mods=mod_ident, mode="add", randomize=timestamp(), **kwargs), title="%s (%s)" % (color, code))) return oc
def set_mods_for_part(rating_key, part_id, language, item_type, mods, mode="add"): plex_item = get_item(rating_key) if not plex_item: return current_sub, stored_subs, storage = get_current_sub(rating_key, part_id, language, plex_item=plex_item) if mode == "add": for mod in mods: identifier, args = SubtitleModifications.parse_identifier(mod) mod_class = SubtitleModifications.get_mod_class(identifier) if identifier not in mod_registry.mods_available: raise NotImplementedError("Mod unknown or not registered") # clean exclusive mods if mod_class.exclusive and current_sub.mods: for current_mod in current_sub.mods[:]: if current_mod.startswith(identifier): current_sub.mods.remove(current_mod) Log.Info("Removing superseded mod %s" % current_mod) current_sub.add_mod(mod) elif mode == "clear": current_sub.add_mod(None) elif mode == "remove": for mod in mods: current_sub.mods.remove(mod) elif mode == "remove_last": if current_sub.mods: current_sub.mods.pop() else: raise NotImplementedError("Wrong mode given") save_stored_sub(current_sub, rating_key, part_id, language, item_type, plex_item=plex_item, storage=storage, stored_subs=stored_subs) storage.save(stored_subs) storage.destroy()
def SubtitleColorModMenu(**kwargs): kwargs.pop("randomize") color_mod = SubtitleModifications.get_mod_class("color") oc = SubFolderObjectContainer(title2=kwargs["title"], replace_parent=True) oc.add(DirectoryObject( key=Callback(SubtitleModificationsMenu, randomize=timestamp(), **kwargs), title=_("< Back to subtitle modification menu") )) for color, code in color_mod.colors.iteritems(): mod_ident = SubtitleModifications.get_mod_signature("color", **{"name": color}) oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=mod_ident, mode="add", randomize=timestamp(), **kwargs), title="%s (%s)" % (color, code) )) return oc
def SubtitleModificationsMenu(**kwargs): rating_key = kwargs["rating_key"] part_id = kwargs["part_id"] language = kwargs["language"] current_sub, stored_subs, storage = get_current_sub(rating_key, part_id, language) kwargs.pop("randomize") current_mods = current_sub.mods or [] oc = SubFolderObjectContainer(title2=kwargs["title"], replace_parent=True) from interface.item_details import SubtitleOptionsMenu oc.add(DirectoryObject( key=Callback(SubtitleOptionsMenu, randomize=timestamp(), **kwargs), title=u"< Back to subtitle options for: %s" % kwargs["title"], summary=kwargs["current_data"], thumb=default_thumb )) for identifier, mod in mod_registry.mods.iteritems(): if mod.advanced: continue if mod.exclusive and identifier in current_mods: continue oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=identifier, mode="add", randomize=timestamp(), **kwargs), title=pad_title(mod.description), summary=mod.long_description or "" )) fps_mod = SubtitleModifications.get_mod_class("change_FPS") oc.add(DirectoryObject( key=Callback(SubtitleFPSModMenu, randomize=timestamp(), **kwargs), title=pad_title(fps_mod.description), summary=fps_mod.long_description or "" )) shift_mod = SubtitleModifications.get_mod_class("shift_offset") oc.add(DirectoryObject( key=Callback(SubtitleShiftModUnitMenu, randomize=timestamp(), **kwargs), title=pad_title(shift_mod.description), summary=shift_mod.long_description or "" )) color_mod = SubtitleModifications.get_mod_class("color") oc.add(DirectoryObject( key=Callback(SubtitleColorModMenu, randomize=timestamp(), **kwargs), title=pad_title(color_mod.description), summary=color_mod.long_description or "" )) if current_mods: oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=None, mode="remove_last", randomize=timestamp(), **kwargs), title=pad_title("Remove last applied mod (%s)" % current_mods[-1]), summary=u"Currently applied mods: %s" % (", ".join(current_mods) if current_mods else "none") )) oc.add(DirectoryObject( key=Callback(SubtitleListMods, randomize=timestamp(), **kwargs), title=pad_title("Manage applied mods"), summary=u"Currently applied mods: %s" % (", ".join(current_mods)) )) oc.add(DirectoryObject( key=Callback(SubtitleReapplyMods, randomize=timestamp(), **kwargs), title=pad_title("Reapply applied mods"), summary=u"Currently applied mods: %s" % (", ".join(current_mods) if current_mods else "none") )) oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=None, mode="clear", randomize=timestamp(), **kwargs), title=pad_title("Restore original version"), summary=u"Currently applied mods: %s" % (", ".join(current_mods) if current_mods else "none") )) storage.destroy() return oc
def SubtitleModificationsMenu(**kwargs): rating_key = kwargs["rating_key"] part_id = kwargs["part_id"] language = kwargs["language"] lang_instance = Language.fromietf(language) current_sub, stored_subs, storage = get_current_sub(rating_key, part_id, language) kwargs.pop("randomize") current_mods = current_sub.mods or [] oc = SubFolderObjectContainer(title2=kwargs["title"], replace_parent=True) from interface.item_details import SubtitleOptionsMenu oc.add(DirectoryObject( key=Callback(SubtitleOptionsMenu, randomize=timestamp(), **kwargs), title=_(u"< Back to subtitle options for: %s", kwargs["title"]), summary=unicode(kwargs["current_data"]), thumb=default_thumb )) for identifier, mod in mod_registry.mods.iteritems(): if mod.advanced: continue if mod.exclusive and identifier in current_mods: continue if mod.languages and lang_instance not in mod.languages: continue oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=identifier, mode="add", randomize=timestamp(), **kwargs), title=pad_title(_(mod.description)), summary=_(mod.long_description) or "" )) fps_mod = SubtitleModifications.get_mod_class("change_FPS") oc.add(DirectoryObject( key=Callback(SubtitleFPSModMenu, randomize=timestamp(), **kwargs), title=pad_title(_(fps_mod.description)), summary=_(fps_mod.long_description) or "" )) shift_mod = SubtitleModifications.get_mod_class("shift_offset") oc.add(DirectoryObject( key=Callback(SubtitleShiftModUnitMenu, randomize=timestamp(), **kwargs), title=pad_title(_(shift_mod.description)), summary=_(shift_mod.long_description) or "" )) color_mod = SubtitleModifications.get_mod_class("color") oc.add(DirectoryObject( key=Callback(SubtitleColorModMenu, randomize=timestamp(), **kwargs), title=pad_title(_(color_mod.description)), summary=_(color_mod.long_description) or "" )) if current_mods: oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=None, mode="remove_last", randomize=timestamp(), **kwargs), title=pad_title(_("Remove last applied mod (%s)", current_mods[-1])), summary=_(u"Currently applied mods: %(mod_list)s", mod_list=", ".join(current_mods) if current_mods else _("none")) )) oc.add(DirectoryObject( key=Callback(SubtitleListMods, randomize=timestamp(), **kwargs), title=pad_title(_("Manage applied mods")), summary=_(u"Currently applied mods: %(mod_list)s", mod_list=", ".join(current_mods)) )) oc.add(DirectoryObject( key=Callback(SubtitleReapplyMods, randomize=timestamp(), **kwargs), title=pad_title(_("Reapply applied mods")), summary=_(u"Currently applied mods: %(mod_list)s", mod_list=", ".join(current_mods) if current_mods else _("none")) )) oc.add(DirectoryObject( key=Callback(SubtitleSetMods, mods=None, mode="clear", randomize=timestamp(), **kwargs), title=pad_title(_("Restore original version")), summary=_(u"Currently applied mods: %(mod_list)s", mod_list=", ".join(current_mods) if current_mods else _("none")) )) storage.destroy() return oc
def set_mods_for_part(rating_key, part_id, language, item_type, mods, mode="add"): from support.plex_media import get_plex_metadata from support.scanning import scan_videos from support.storage import save_subtitles plex_item = get_item(rating_key) if not plex_item: return current_sub, stored_subs, storage = get_current_sub(rating_key, part_id, language, plex_item=plex_item) if mode == "add": for mod in mods: identifier, args = SubtitleModifications.parse_identifier(mod) mod_class = SubtitleModifications.get_mod_class(identifier) if identifier not in mod_registry.mods_available: raise NotImplementedError("Mod unknown or not registered") # clean exclusive mods if mod_class.exclusive and current_sub.mods: for current_mod in current_sub.mods[:]: if current_mod.startswith(identifier): current_sub.mods.remove(current_mod) Log.Info("Removing superseded mod %s" % current_mod) current_sub.add_mod(mod) elif mode == "clear": current_sub.add_mod(None) elif mode == "remove": for mod in mods: current_sub.mods.remove(mod) elif mode == "remove_last": if current_sub.mods: current_sub.mods.pop() else: raise NotImplementedError("Wrong mode given") storage.save(stored_subs) try: metadata = get_plex_metadata(rating_key, part_id, item_type, plex_item=plex_item) except PartUnknownException: return scanned_parts = scan_videos( [metadata], kind="series" if item_type == "episode" else "movie", ignore_all=True, no_refining=True) video, plex_part = scanned_parts.items()[0] subtitle = ModifiedSubtitle(language, mods=current_sub.mods) subtitle.content = current_sub.content if current_sub.encoding: # thanks plex setattr(subtitle, "_guessed_encoding", current_sub.encoding) if current_sub.encoding != "utf-8": subtitle.normalize() current_sub.content = subtitle.content current_sub.encoding = "utf-8" storage.save(stored_subs) storage.destroy() subtitle.plex_media_fps = plex_part.fps subtitle.page_link = "modify subtitles with: %s" % (", ".join( current_sub.mods) if current_sub.mods else "none") subtitle.language = language subtitle.id = current_sub.id try: save_subtitles(scanned_parts, {video: [subtitle]}, mode="m", bare_save=True) Log.Debug("Modified %s subtitle for: %s:%s with: %s", language.name, rating_key, part_id, ", ".join(current_sub.mods) if current_sub.mods else "none") except: Log.Error("Something went wrong when modifying subtitle: %s", traceback.format_exc())