def save_subtitles(scanned_video_part_map, downloaded_subtitles, mode="a"): meta_fallback = False save_successful = False storage = "metadata" if Prefs['subtitles.save.filesystem']: storage = "filesystem" try: Log.Debug("Using filesystem as subtitle storage") save_subtitles_to_file(downloaded_subtitles) except OSError: if Prefs["subtitles.save.metadata_fallback"]: meta_fallback = True else: raise else: save_successful = True if not Prefs['subtitles.save.filesystem'] or meta_fallback: if meta_fallback: Log.Debug( "Using metadata as subtitle storage, because filesystem storage failed" ) else: Log.Debug("Using metadata as subtitle storage") save_successful = save_subtitles_to_metadata(scanned_video_part_map, downloaded_subtitles) if save_successful and config.notify_executable: notify_executable(config.notify_executable, scanned_video_part_map, downloaded_subtitles, storage) store_subtitle_info(scanned_video_part_map, downloaded_subtitles, storage, mode=mode)
def save_subtitles(scanned_video_part_map, downloaded_subtitles, mode="a", bare_save=False, mods=None, set_current=True): """ :param set_current: save the subtitle as the current one :param scanned_video_part_map: :param downloaded_subtitles: :param mode: :param bare_save: don't trigger anything; don't store information :param mods: enabled mods :return: """ meta_fallback = False save_successful = False # big fixme: scanned_video_part_map isn't needed to the current extent. rewrite. if mods: for video, video_subtitles in downloaded_subtitles.items(): if not video_subtitles: continue for subtitle in video_subtitles: Log.Info("Applying mods: %s to %s", mods, subtitle) subtitle.mods = mods subtitle.plex_media_fps = video.fps storage = "metadata" save_to_fs = cast_bool(Prefs['subtitles.save.filesystem']) if save_to_fs: storage = "filesystem" if set_current: if save_to_fs: try: Log.Debug("Using filesystem as subtitle storage") save_subtitles_to_file(downloaded_subtitles) except OSError: if cast_bool(Prefs["subtitles.save.metadata_fallback"]): meta_fallback = True storage = "metadata" else: raise else: save_successful = True if not save_to_fs or meta_fallback: if meta_fallback: Log.Debug("Using metadata as subtitle storage, because filesystem storage failed") else: Log.Debug("Using metadata as subtitle storage") save_successful = save_subtitles_to_metadata(scanned_video_part_map, downloaded_subtitles) if not bare_save and save_successful and config.notify_executable: notify_executable(config.notify_executable, scanned_video_part_map, downloaded_subtitles, storage) if (not bare_save and save_successful) or not set_current: store_subtitle_info(scanned_video_part_map, downloaded_subtitles, storage, mode=mode, set_current=set_current) return save_successful
def save_subtitles(scanned_video_part_map, downloaded_subtitles, mode="a", bare_save=False, mods=None): """ :param scanned_video_part_map: :param downloaded_subtitles: :param mode: :param bare_save: don't trigger anything; don't store information :param mods: enabled mods :return: """ meta_fallback = False save_successful = False if mods: for video, video_subtitles in downloaded_subtitles.items(): if not video_subtitles: continue for subtitle in video_subtitles: Log.Info("Applying mods: %s to %s", mods, subtitle) subtitle.mods = mods subtitle.plex_media_fps = video.fps storage = "metadata" if Prefs['subtitles.save.filesystem']: storage = "filesystem" try: Log.Debug("Using filesystem as subtitle storage") save_subtitles_to_file(downloaded_subtitles) except OSError: if Prefs["subtitles.save.metadata_fallback"]: meta_fallback = True else: raise else: save_successful = True if not Prefs['subtitles.save.filesystem'] or meta_fallback: if meta_fallback: Log.Debug( "Using metadata as subtitle storage, because filesystem storage failed" ) else: Log.Debug("Using metadata as subtitle storage") save_successful = save_subtitles_to_metadata(scanned_video_part_map, downloaded_subtitles) if not bare_save and save_successful and config.notify_executable: notify_executable(config.notify_executable, scanned_video_part_map, downloaded_subtitles, storage) if not bare_save and save_successful: store_subtitle_info(scanned_video_part_map, downloaded_subtitles, storage, mode=mode) return save_successful