Ejemplo n.º 1
0
def ListEmbeddedSubsForItemMenu(**kwargs):
    rating_key = kwargs["rating_key"]
    part_id = kwargs["part_id"]
    title = kwargs["title"]
    kwargs.pop("randomize")

    oc = SubFolderObjectContainer(title2=title, replace_parent=True)

    oc.add(
        DirectoryObject(key=Callback(ItemDetailsMenu,
                                     rating_key=kwargs["rating_key"],
                                     item_title=kwargs["item_title"],
                                     base_title=kwargs["base_title"],
                                     title=kwargs["item_title"],
                                     randomize=timestamp()),
                        title=u"< Back to %s" % kwargs["title"],
                        thumb=default_thumb))

    plex_item = get_item(rating_key)
    part = get_part(plex_item, part_id)

    if part:
        for stream_data in get_embedded_subtitle_streams(
                part, skip_duplicate_unknown=False):
            language = stream_data["language"]
            is_unknown = stream_data["is_unknown"]
            stream = stream_data["stream"]
            is_forced = stream_data["is_forced"]

            if language:
                oc.add(
                    DirectoryObject(
                        key=Callback(TriggerExtractEmbeddedSubForItemMenu,
                                     randomize=timestamp(),
                                     stream_index=str(stream.index),
                                     language=language,
                                     with_mods=True,
                                     **kwargs),
                        title=u"Extract stream %s, "
                        u"%s%s%s%s with default mods" %
                        (stream.index, display_language(language),
                         " (unknown)" if is_unknown else "",
                         " (forced)" if is_forced else "",
                         " (\"%s\")" % stream.title if stream.title else ""),
                    ))
                oc.add(
                    DirectoryObject(
                        key=Callback(TriggerExtractEmbeddedSubForItemMenu,
                                     randomize=timestamp(),
                                     stream_index=str(stream.index),
                                     language=language,
                                     **kwargs),
                        title=u"Extract stream %s, %s%s%s%s" %
                        (stream.index, display_language(language),
                         " (unknown)" if is_unknown else "",
                         " (forced)" if is_forced else "",
                         " (\"%s\")" % stream.title if stream.title else ""),
                    ))
    return oc
Ejemplo n.º 2
0
def ListEmbeddedSubsForItemMenu(**kwargs):
    rating_key = kwargs["rating_key"]
    part_id = kwargs["part_id"]
    title = kwargs["title"]
    kwargs.pop("randomize")

    oc = SubFolderObjectContainer(title2=title, replace_parent=True)

    oc.add(DirectoryObject(
        key=Callback(ItemDetailsMenu, rating_key=kwargs["rating_key"], item_title=kwargs["item_title"],
                     base_title=kwargs["base_title"], title=kwargs["item_title"], randomize=timestamp()),
        title=_("< Back to %s", kwargs["title"]),
        thumb=default_thumb
    ))

    plex_item = get_item(rating_key)
    part = get_part(plex_item, part_id)

    if part:
        for stream_data in get_embedded_subtitle_streams(part, skip_duplicate_unknown=False):
            language = stream_data["language"]
            is_unknown = stream_data["is_unknown"]
            stream = stream_data["stream"]
            is_forced = stream_data["is_forced"]

            if language:
                oc.add(DirectoryObject(
                    key=Callback(TriggerExtractEmbeddedSubForItemMenu, randomize=timestamp(),
                                 stream_index=str(stream.index), language=language, with_mods=True, **kwargs),
                    title=_(u"Extract stream %(stream_index)s, %(language)s%(unknown_state)s%(forced_state)s"
                            u"%(stream_title)s with default mods",
                            stream_index=stream.index,
                            language=display_language(language),
                            unknown_state=_(" (unknown)") if is_unknown else "",
                            forced_state=_(" (forced)") if is_forced else "",
                            stream_title=" (\"%s\")" % stream.title if stream.title else ""),
                ))
                oc.add(DirectoryObject(
                    key=Callback(TriggerExtractEmbeddedSubForItemMenu, randomize=timestamp(),
                                 stream_index=str(stream.index), language=language, **kwargs),
                    title=_(u"Extract stream %(stream_index)s, %(language)s%(unknown_state)s%(forced_state)s"
                            u"%(stream_title)s",
                            stream_index=stream.index,
                            language=display_language(language),
                            unknown_state=_(" (unknown)") if is_unknown else "",
                            forced_state=_(" (forced)") if is_forced else "",
                            stream_title=" (\"%s\")" % stream.title if stream.title else ""),
                ))
    return oc
Ejemplo n.º 3
0
def extract_embedded_sub(**kwargs):
    rating_key = kwargs["rating_key"]
    part_id = kwargs.pop("part_id")
    stream_index = kwargs.pop("stream_index")
    with_mods = kwargs.pop("with_mods", False)
    language = Language.fromietf(kwargs.pop("language"))
    refresh = kwargs.pop("refresh", True)
    set_current = kwargs.pop("set_current", True)

    plex_item = kwargs.pop("plex_item", get_item(rating_key))
    item_type = get_item_kind_from_item(plex_item)
    part = kwargs.pop("part", get_part(plex_item, part_id))
    scanned_videos = kwargs.pop("scanned_videos", None)
    extract_mode = kwargs.pop("extract_mode", "a")

    any_successful = False

    if part:
        if not scanned_videos:
            metadata = get_plex_metadata(rating_key,
                                         part_id,
                                         item_type,
                                         plex_item=plex_item)
            scanned_videos = scan_videos([metadata],
                                         ignore_all=True,
                                         skip_hashing=True)

        for stream in part.streams:
            # subtitle stream
            if str(stream.index) == stream_index:
                is_forced = is_stream_forced(stream)
                bn = os.path.basename(part.file)

                set_refresh_menu_state(
                    _(u"Extracting subtitle %(stream_index)s of %(filename)s",
                      stream_index=stream_index,
                      filename=bn))
                Log.Info(u"Extracting stream %s (%s) of %s", stream_index,
                         str(language), bn)

                out_codec = stream.codec if stream.codec != "mov_text" else "srt"

                args = [
                    config.plex_transcoder, "-i", part.file, "-map",
                    "0:%s" % stream_index, "-f", out_codec, "-"
                ]
                output = None
                try:
                    output = subprocess.check_output(quote_args(args),
                                                     stderr=subprocess.PIPE,
                                                     shell=True)
                except:
                    Log.Error("Extraction failed: %s", traceback.format_exc())

                if output:
                    subtitle = ModifiedSubtitle(
                        language,
                        mods=config.default_mods if with_mods else None)
                    subtitle.content = output
                    subtitle.provider_name = "embedded"
                    subtitle.id = "stream_%s" % stream_index
                    subtitle.score = 0
                    subtitle.set_encoding("utf-8")

                    # fixme: speedup video; only video.name is needed
                    video = scanned_videos.keys()[0]
                    save_successful = save_subtitles(scanned_videos,
                                                     {video: [subtitle]},
                                                     mode="m",
                                                     set_current=set_current)
                    set_refresh_menu_state(None)

                    if save_successful and refresh:
                        refresh_item(rating_key)

                    # add item to history
                    item_title = get_title_for_video_metadata(
                        video.plexapi_metadata,
                        add_section_title=False,
                        add_episode_title=True)

                    history = get_history()
                    history.add(
                        item_title,
                        video.id,
                        section_title=video.plexapi_metadata["section"],
                        thumb=video.plexapi_metadata["super_thumb"],
                        subtitle=subtitle,
                        mode=extract_mode)
                    history.destroy()

                    any_successful = True

    return any_successful
Ejemplo n.º 4
0
def extract_embedded_sub(**kwargs):
    rating_key = kwargs["rating_key"]
    part_id = kwargs.pop("part_id")
    stream_index = kwargs.pop("stream_index")
    with_mods = kwargs.pop("with_mods", False)
    language = Language.fromietf(kwargs.pop("language"))
    refresh = kwargs.pop("refresh", True)
    set_current = kwargs.pop("set_current", True)

    plex_item = kwargs.pop("plex_item", get_item(rating_key))
    item_type = get_item_kind_from_item(plex_item)
    part = kwargs.pop("part", get_part(plex_item, part_id))
    scanned_videos = kwargs.pop("scanned_videos", None)
    extract_mode = kwargs.pop("extract_mode", "a")

    any_successful = False

    if part:
        if not scanned_videos:
            metadata = get_plex_metadata(rating_key, part_id, item_type, plex_item=plex_item)
            scanned_videos = scan_videos([metadata], ignore_all=True, skip_hashing=True)

        for stream in part.streams:
            # subtitle stream
            if str(stream.index) == stream_index:
                is_forced = is_stream_forced(stream)
                bn = os.path.basename(part.file)

                set_refresh_menu_state(_(u"Extracting subtitle %(stream_index)s of %(filename)s",
                                         stream_index=stream_index,
                                         filename=bn))
                Log.Info(u"Extracting stream %s (%s) of %s", stream_index, str(language), bn)

                out_codec = stream.codec if stream.codec != "mov_text" else "srt"

                args = [
                    config.plex_transcoder, "-i", part.file, "-map", "0:%s" % stream_index, "-f", out_codec, "-"
                ]

                cmdline = quote_args(args)
                Log.Debug(u"Calling: %s", cmdline)
                if mswindows:
                    Log.Debug("MSWindows: Fixing encoding")
                    cmdline = cmdline.encode("mbcs")

                output = None
                try:
                    output = subprocess.check_output(cmdline, stderr=subprocess.PIPE, shell=True)
                except:
                    Log.Error("Extraction failed: %s", traceback.format_exc())

                if output:
                    subtitle = ModifiedSubtitle(language, mods=config.default_mods if with_mods else None)
                    subtitle.content = output
                    subtitle.provider_name = "embedded"
                    subtitle.id = "stream_%s" % stream_index
                    subtitle.score = 0
                    subtitle.set_encoding("utf-8")

                    # fixme: speedup video; only video.name is needed
                    video = scanned_videos.keys()[0]
                    save_successful = save_subtitles(scanned_videos, {video: [subtitle]}, mode="m",
                                                     set_current=set_current)
                    set_refresh_menu_state(None)

                    if save_successful and refresh:
                        refresh_item(rating_key)

                    # add item to history
                    item_title = get_title_for_video_metadata(video.plexapi_metadata,
                                                              add_section_title=False, add_episode_title=True)

                    history = get_history()
                    history.add(item_title, video.id, section_title=video.plexapi_metadata["section"],
                                thumb=video.plexapi_metadata["super_thumb"],
                                subtitle=subtitle, mode=extract_mode)
                    history.destroy()

                    any_successful = True

    return any_successful
Ejemplo n.º 5
0
def extract_embedded_sub(**kwargs):
    rating_key = kwargs["rating_key"]
    part_id = kwargs.pop("part_id")
    stream_index = kwargs.pop("stream_index")
    with_mods = kwargs.pop("with_mods", False)
    language = Language.fromietf(kwargs.pop("language"))
    refresh = kwargs.pop("refresh", True)
    set_current = kwargs.pop("set_current", True)

    plex_item = get_item(rating_key)
    item_type = get_item_kind_from_item(plex_item)
    part = get_part(plex_item, part_id)

    if part:
        metadata = get_plex_metadata(rating_key,
                                     part_id,
                                     item_type,
                                     plex_item=plex_item)
        scanned_parts = scan_videos([metadata],
                                    ignore_all=True,
                                    skip_hashing=True)
        for stream in part.streams:
            # subtitle stream
            if str(stream.index) == stream_index:
                forced = stream.forced
                bn = os.path.basename(part.file)

                set_refresh_menu_state(u"Extracting subtitle %s of %s" %
                                       (stream_index, bn))
                Log.Info(u"Extracting stream %s (%s) of %s", stream_index,
                         display_language(language), bn)

                args = [
                    config.plex_transcoder, "-i", part.file, "-map",
                    "0:%s" % stream_index, "-f", "srt", "-"
                ]
                output = None
                try:
                    output = subprocess.check_output(quote_args(args),
                                                     stderr=subprocess.PIPE,
                                                     shell=True)
                except:
                    Log.Error("Extraction failed: %s", traceback.format_exc())

                if output:
                    subtitle = ModifiedSubtitle(
                        language,
                        mods=config.default_mods if with_mods else None)
                    subtitle.content = output
                    subtitle.provider_name = "embedded"
                    subtitle.id = "stream_%s" % stream_index
                    subtitle.score = 0
                    subtitle.set_encoding("utf-8")

                    # fixme: speedup video; only video.name is needed
                    save_successful = save_subtitles(
                        scanned_parts, {scanned_parts.keys()[0]: [subtitle]},
                        mode="m",
                        set_current=set_current)
                    set_refresh_menu_state(None)

                    if save_successful and refresh:
                        refresh_item(rating_key)