def get_embedded_subtitle_streams(part, requested_language=None, skip_duplicate_unknown=True, get_forced=None): streams = [] has_unknown = False for stream in part.streams: # subtitle stream if stream.stream_type == 3 and not stream.stream_key and stream.codec in TEXT_SUBTITLE_EXTS: language = helpers.get_language_from_stream(stream.language_code) is_unknown = False found_requested_language = requested_language and requested_language == language is_forced = helpers.is_stream_forced(stream) if get_forced is not None: if (get_forced and not is_forced) or (not get_forced and is_forced): continue if not language and config.treat_und_as_first: # only consider first unknown subtitle stream if has_unknown and skip_duplicate_unknown: continue language = list(config.lang_list)[0] is_unknown = True has_unknown = True if not requested_language or found_requested_language or has_unknown: streams.append({"stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced}) if found_requested_language: break return streams
def get_embedded_subtitle_streams(part, requested_language=None, skip_duplicate_unknown=True, skip_unknown=False): streams = [] streams_unknown = [] all_streams = [] has_unknown = False found_requested_language = False update_stream_info(part) for stream in part.streams: # subtitle stream if stream.stream_type == 3 and not stream.stream_key and stream.codec in TEXT_SUBTITLE_EXTS: is_forced = is_stream_forced(stream) language = helpers.get_language_from_stream(stream.language_code) if language: language = Language.rebuild(language, forced=is_forced) is_unknown = False found_requested_language = requested_language and requested_language == language stream_data = None if not language: # only consider first unknown subtitle stream if config.treat_und_as_first: if has_unknown and skip_duplicate_unknown: Log.Debug("skipping duplicate unknown") continue language = Language.rebuild(list(config.lang_list)[0], forced=is_forced) else: language = None is_unknown = True has_unknown = True stream_data = {"stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced} streams_unknown.append(stream_data) if not requested_language or found_requested_language: stream_data = {"stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced} streams.append(stream_data) if found_requested_language: break if stream_data: all_streams.append(stream_data) if requested_language: if streams_unknown and not found_requested_language and not skip_unknown: streams = streams_unknown else: streams = all_streams return streams
def get_embedded_subtitle_streams(part, requested_language=None, skip_duplicate_unknown=True): streams = [] streams_unknown = [] has_unknown = False found_requested_language = False for stream in part.streams: # subtitle stream if stream.stream_type == 3 and not stream.stream_key and stream.codec in TEXT_SUBTITLE_EXTS: is_forced = helpers.is_stream_forced(stream) language = helpers.get_language_from_stream(stream.language_code) if language: language = Language.rebuild(language, forced=is_forced) is_unknown = False found_requested_language = requested_language and requested_language == language if not language and config.treat_und_as_first: # only consider first unknown subtitle stream if has_unknown and skip_duplicate_unknown: continue language = Language.rebuild(list(config.lang_list)[0], forced=is_forced) is_unknown = True has_unknown = True streams_unknown.append({ "stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced }) if not requested_language or found_requested_language: streams.append({ "stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced }) if found_requested_language: break if streams_unknown and not found_requested_language: streams = streams_unknown return streams
def get_embedded_subtitle_streams(part, requested_language=None, skip_duplicate_unknown=True, skip_unknown=False): streams = [] streams_unknown = [] has_unknown = False found_requested_language = False for stream in part.streams: # subtitle stream if stream.stream_type == 3 and not stream.stream_key and stream.codec in TEXT_SUBTITLE_EXTS: is_forced = helpers.is_stream_forced(stream) language = helpers.get_language_from_stream(stream.language_code) if language: language = Language.rebuild(language, forced=is_forced) is_unknown = False found_requested_language = requested_language and requested_language == language if not language and config.treat_und_as_first: # only consider first unknown subtitle stream if has_unknown and skip_duplicate_unknown: continue language = Language.rebuild(list(config.lang_list)[0], forced=is_forced) is_unknown = True has_unknown = True streams_unknown.append({"stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced}) if not requested_language or found_requested_language: streams.append({"stream": stream, "is_unknown": is_unknown, "language": language, "is_forced": is_forced}) if found_requested_language: break if streams_unknown and not found_requested_language and not skip_unknown: streams = streams_unknown return streams
def scan_video(pms_video_info, ignore_all=False, hints=None, rating_key=None, providers=None, skip_hashing=False): """ returnes a subliminal/guessit-refined parsed video :param pms_video_info: :param ignore_all: :param hints: :param rating_key: :return: """ embedded_subtitles = not ignore_all and Prefs['subtitles.scan.embedded'] external_subtitles = not ignore_all and Prefs['subtitles.scan.external'] plex_part = pms_video_info["plex_part"] if ignore_all: Log.Debug("Force refresh intended.") Log.Debug( "Scanning video: %s, external_subtitles=%s, embedded_subtitles=%s" % (plex_part.file, external_subtitles, embedded_subtitles)) known_embedded = [] parts = [] for media in list(Plex["library"].metadata(rating_key))[0].media: parts += media.parts plexpy_part = None for part in parts: if int(part.id) == int(plex_part.id): plexpy_part = part # embedded subtitles if plexpy_part: for stream in plexpy_part.streams: # subtitle stream if stream.stream_type == 3: if (config.forced_only and getattr(stream, "forced")) or \ (not config.forced_only and not getattr(stream, "forced")): # embedded subtitle # fixme: tap into external subtitles here instead of scanning for ourselves later? if not stream.stream_key and stream.codec: if config.exotic_ext or stream.codec.lower( ) in TEXT_SUBTITLE_EXTS: lang = helpers.get_language_from_stream( stream.language_code) # treat unknown language as lang1? if not lang and config.treat_und_as_first: lang = list(config.lang_list)[0] if lang: known_embedded.append(lang.alpha3) else: Log.Warn("Part %s missing of %s, not able to scan internal streams", plex_part.id, rating_key) subtitle_storage = get_subtitle_storage() stored_subs = subtitle_storage.load(rating_key) subtitle_storage.destroy() try: # get basic video info scan (filename) # video = parse_video(plex_part.file, pms_video_info, hints, external_subtitles=external_subtitles, # embedded_subtitles=embedded_subtitles, known_embedded=known_embedded, # forced_only=config.forced_only, no_refining=no_refining, ignore_all=ignore_all, # stored_subs=stored_subs, refiner_settings=config.refiner_settings, providers=providers, # skip_hashing=config.low_impact_mode) video = parse_video(plex_part.file, hints, skip_hashing=config.low_impact_mode or skip_hashing, providers=providers) if not ignore_all: set_existing_languages(video, pms_video_info, external_subtitles=external_subtitles, embedded_subtitles=embedded_subtitles, known_embedded=known_embedded, forced_only=config.forced_only, stored_subs=stored_subs, languages=config.lang_list, only_one=config.only_one) # add video fps info video.fps = plex_part.fps return video except ValueError: Log.Warn("File could not be guessed: %s: %s", plex_part.file, traceback.format_exc())