示例#1
0
def season_extract_embedded(rating_key, requested_language, with_mods=False, force=False):
    # get stored subtitle info for item id
    subtitle_storage = get_subtitle_storage()

    try:
        for data in get_all_items(key="children", value=rating_key, base="library/metadata"):
            item = get_item(data[MI_KEY])
            if item:
                stored_subs = subtitle_storage.load_or_new(item)
                for part in get_all_parts(item):
                    embedded_subs = stored_subs.get_by_provider(part.id, requested_language, "embedded")
                    current = stored_subs.get_any(part.id, requested_language)
                    if not embedded_subs or force:
                        stream_data = get_embedded_subtitle_streams(part, requested_language=requested_language,
                                                                    get_forced=config.forced_only)
                        if stream_data:
                            stream = stream_data[0]["stream"]

                            set_current = not current or force
                            refresh = not current

                            extract_embedded_sub(rating_key=item.rating_key, part_id=part.id,
                                                 stream_index=str(stream.index), set_current=set_current,
                                                 refresh=refresh, language=requested_language, with_mods=with_mods)
    finally:
        subtitle_storage.destroy()
示例#2
0
def season_extract_embedded(rating_key, requested_language, with_mods=False, force=False):
    # get stored subtitle info for item id
    subtitle_storage = get_subtitle_storage()

    try:
        for data in get_all_items(key="children", value=rating_key, base="library/metadata"):
            item = get_item(data[MI_KEY])
            if item:
                stored_subs = subtitle_storage.load_or_new(item)
                for part in get_all_parts(item):
                    embedded_subs = stored_subs.get_by_provider(part.id, requested_language, "embedded")
                    current = stored_subs.get_any(part.id, requested_language)
                    if not embedded_subs or force:
                        stream_data = get_embedded_subtitle_streams(part, requested_language=requested_language)
                        if stream_data:
                            stream = stream_data[0]["stream"]

                            set_current = not current or force
                            refresh = not current

                            extract_embedded_sub(rating_key=item.rating_key, part_id=part.id,
                                                 stream_index=str(stream.index), set_current=set_current,
                                                 refresh=refresh, language=requested_language, with_mods=with_mods,
                                                 extract_mode="m")
    finally:
        subtitle_storage.destroy()
示例#3
0
def agent_extract_embedded(video_part_map, set_as_existing=False):
    try:
        subtitle_storage = get_subtitle_storage()

        to_extract = []
        item_count = 0

        threads = []

        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
                used_one_known_stream = False
                for requested_language in config.lang_list:
                    skip_unknown = used_one_unknown_stream or used_one_known_stream
                    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=skip_unknown)

                        if stream_data and stream_data[0]["language"]:
                            stream = stream_data[0]["stream"]
                            if stream_data[0]["is_unknown"]:
                                used_one_unknown_stream = True
                            else:
                                used_one_known_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"]
                            ) or set_as_existing:
                                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)
            threads.append(
                Thread.Create(
                    multi_extract_embedded,
                    stream_list=to_extract,
                    refresh=True,
                    with_mods=True,
                    single_thread=not config.advanced.auto_extract_multithread)
            )
            return threads
    except:
        Log.Error(
            "Something went wrong when auto-extracting subtitles, continuing: %s",
            traceback.format_exc())