コード例 #1
0
ファイル: download.py プロジェクト: u20024804/Sub-Zero.bundle
def get_missing_languages(video, part):
    languages_list = config.get_lang_list(ordered=True)
    languages = set(languages_list)
    valid_langs_in_media = set()

    if Prefs["subtitles.when"] != "Always":
        valid_langs_in_media = audio_streams_match_languages(video, languages_list)
        languages = languages.difference(valid_langs_in_media)
        if languages:
            Log.Debug("Languages missing after taking the audio streams into account: %s" % languages)

    if valid_langs_in_media and not languages:
        Log.Debug("Skipping subtitle search for %s, audio streams are in correct language(s)",
                  video)
        return set()

    # should we treat IETF as alpha3? (ditch the country part)
    alpha3_map = {}
    if config.ietf_as_alpha3:
        for language in languages:
            if language.country:
                alpha3_map[language.alpha3] = language.country
                language.country = None

    have_languages = video.subtitle_languages.copy()
    if config.ietf_as_alpha3:
        for language in have_languages:
            if language.country:
                alpha3_map[language.alpha3] = language.country
                language.country = None

    missing_languages = (languages - have_languages)

    # all languages are found if we either really have subs for all languages or we only want to have exactly one language
    # and we've only found one (the case for a selected language, Prefs['subtitles.only_one'] (one found sub matches any language))
    found_one_which_is_enough = len(video.subtitle_languages) >= 1 and Prefs['subtitles.only_one']
    if not missing_languages or found_one_which_is_enough:
        if found_one_which_is_enough:
            Log.Debug('Only one language was requested, and we\'ve got a subtitle for %s', video)
        else:
            Log.Debug('All languages %r exist for %s', languages, video)
        return False

    # re-add country codes to the missing languages, in case we've removed them above
    if config.ietf_as_alpha3:
        for language in languages:
            language.country = alpha3_map.get(language.alpha3, None)

    return missing_languages
コード例 #2
0
ファイル: __init__.py プロジェクト: pannal/Sub-Zero.bundle
def agent_extract_embedded(video_part_map):
    try:
        subtitle_storage = get_subtitle_storage()

        to_extract = []
        item_count = 0

        for scanned_video, part_info in video_part_map.iteritems():
            plexapi_item = scanned_video.plexapi_metadata["item"]
            stored_subs = subtitle_storage.load_or_new(plexapi_item)
            valid_langs_in_media = audio_streams_match_languages(scanned_video, config.get_lang_list(ordered=True))

            if not config.lang_list.difference(valid_langs_in_media):
                Log.Debug("Skipping embedded subtitle extraction for %s, audio streams are in correct language(s)",
                          plexapi_item.rating_key)
                continue

            for plexapi_part in get_all_parts(plexapi_item):
                item_count = item_count + 1
                used_one_unknown_stream = False
                for requested_language in config.lang_list:
                    embedded_subs = stored_subs.get_by_provider(plexapi_part.id, requested_language, "embedded")
                    current = stored_subs.get_any(plexapi_part.id, requested_language) or \
                        requested_language in scanned_video.external_subtitle_languages

                    if not embedded_subs:
                        stream_data = get_embedded_subtitle_streams(plexapi_part, requested_language=requested_language,
                                                                    skip_unknown=used_one_unknown_stream)

                        if stream_data:
                            stream = stream_data[0]["stream"]
                            if stream_data[0]["is_unknown"]:
                                used_one_unknown_stream = True

                            to_extract.append(({scanned_video: part_info}, plexapi_part, str(stream.index),
                                               str(requested_language), not current))

                            if not cast_bool(Prefs["subtitles.search_after_autoextract"]):
                                scanned_video.subtitle_languages.update({requested_language})
                    else:
                        Log.Debug("Skipping embedded subtitle extraction for %s, already got %r from %s",
                                  plexapi_item.rating_key, requested_language, embedded_subs[0].id)
        if to_extract:
            Log.Info("Triggering extraction of %d embedded subtitles of %d items", len(to_extract), item_count)
            Thread.Create(multi_extract_embedded, stream_list=to_extract, refresh=True, with_mods=True,
                          single_thread=not config.advanced.auto_extract_multithread)
    except:
        Log.Error("Something went wrong when auto-extracting subtitles, continuing: %s", traceback.format_exc())
コード例 #3
0
def agent_extract_embedded(video_part_map):
    try:
        subtitle_storage = get_subtitle_storage()

        to_extract = []
        item_count = 0

        for scanned_video, part_info in video_part_map.iteritems():
            plexapi_item = scanned_video.plexapi_metadata["item"]
            stored_subs = subtitle_storage.load_or_new(plexapi_item)
            valid_langs_in_media = audio_streams_match_languages(scanned_video, config.get_lang_list(ordered=True))

            if not config.lang_list.difference(valid_langs_in_media):
                Log.Debug("Skipping embedded subtitle extraction for %s, audio streams are in correct language(s)",
                          plexapi_item.rating_key)
                continue

            for plexapi_part in get_all_parts(plexapi_item):
                item_count = item_count + 1
                for requested_language in config.lang_list:
                    embedded_subs = stored_subs.get_by_provider(plexapi_part.id, requested_language, "embedded")
                    current = stored_subs.get_any(plexapi_part.id, requested_language) or \
                        requested_language in scanned_video.external_subtitle_languages

                    if not embedded_subs:
                        stream_data = get_embedded_subtitle_streams(plexapi_part, requested_language=requested_language)

                        if stream_data:
                            stream = stream_data[0]["stream"]

                            to_extract.append(({scanned_video: part_info}, plexapi_part, str(stream.index),
                                               str(requested_language), not current))

                            if not cast_bool(Prefs["subtitles.search_after_autoextract"]):
                                scanned_video.subtitle_languages.update({requested_language})
                    else:
                        Log.Debug("Skipping embedded subtitle extraction for %s, already got %r from %s",
                                  plexapi_item.rating_key, requested_language, embedded_subs[0].id)
        if to_extract:
            Log.Info("Triggering extraction of %d embedded subtitles of %d items", len(to_extract), item_count)
            Thread.Create(multi_extract_embedded, stream_list=to_extract, refresh=True, with_mods=True,
                          single_thread=not config.advanced.auto_extract_multithread)
    except:
        Log.Error("Something went wrong when auto-extracting subtitles, continuing: %s", traceback.format_exc())