예제 #1
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to stretch",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "--no-align",
         help="don't realign subtitles to video frames",
         action="store_true",
     )
     parser.add_argument(
         "-s",
         "--start",
         help="starting subtitle new start timestamp",
         type=lambda value: Pts(api, value),
         required=True,
     )
     parser.add_argument(
         "-e",
         "--end",
         help="ending subtitle new start timestamp",
         type=lambda value: Pts(api, value),
         required=True,
     )
예제 #2
0
    def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "-t",
            "--target",
            help="subtitles to move",
            type=lambda value: SubtitlesSelection(api, value),
            default="selected",
        )

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            "--above",
            dest="method",
            action="store_const",
            const="above",
            help="move subtitles up",
        )
        group.add_argument(
            "--below",
            dest="method",
            action="store_const",
            const="below",
            help="move subtitles down",
        )
        group.add_argument(
            "--gui",
            dest="method",
            action="store_const",
            const="gui",
            help="prompt user for placement position with a GUI dialog",
        )
예제 #3
0
    def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "-o",
            "--origin",
            help="where to insert the subtitle",
            type=lambda value: SubtitlesSelection(api, value),
            default="selected",
        )

        parser.add_argument(
            "--no-align",
            help="don't realign the subtitle to video frames",
            action="store_true",
        )

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            "--before",
            dest="dir",
            action="store_const",
            const="before",
            help="insert before origin",
        )
        group.add_argument(
            "--after",
            dest="dir",
            action="store_const",
            const="after",
            help="insert after origin",
        )
예제 #4
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "-y1",
         help="Starting position of the gradient",
         type=float,
         required=True,
     )
     parser.add_argument(
         "-y2",
         help="Ending position of the gradient",
         type=float,
         required=True,
     )
     parser.add_argument(
         "-c1", help="Source color", type=rgb, required=True
     )
     parser.add_argument(
         "-c2", help="Target color", type=rgb, required=True
     )
     parser.add_argument(
         "--steps", help="How many steps to use", type=int, default=20
     )
     parser.add_argument("--only-print", action="store_true")
예제 #5
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "-e",
         "--engine",
         help="engine to use",
         choices=["bing", "google", "yandex"],
         default="google",
     )
     parser.add_argument(
         "-s",
         "--sleep-time",
         help="time to sleep after each chunk",
         type=int,
         default=3,
     )
     parser.add_argument(metavar="from",
                         dest="source_code",
                         help="source language code")
     parser.add_argument(
         metavar="to",
         dest="target_code",
         help="target language code",
         nargs="?",
         default="en",
     )
예제 #6
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "-m",
         "--max-workers",
         help="number of parallel requests",
         type=int,
         default=5,
     )
     parser.add_argument(
         "-s",
         "--sleep-time",
         help="time to sleep after each chunk",
         type=int,
         default=0,
     )
     parser.add_argument(
         "-a",
         "--audio",
         help="process only audio selection",
         action="store_true",
     )
     parser.add_argument("code", help="language code")
예제 #7
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to delete",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
예제 #8
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument("-m",
                         "--mode",
                         choices=["near", "prev", "next"],
                         default="near")
예제 #9
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to shift",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "--no-align",
         help="don't realign subtitles to video frames",
         action="store_true",
     )
예제 #10
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument("-a",
                         "--amount",
                         help="amount to blur",
                         type=float,
                         default=0.75)
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
예제 #11
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to merge",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "--invisible",
         help="use alternative karaoke transformation",
         action="store_true",
     )
예제 #12
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "-l",
         "--lang",
         "--language",
         help="language used for detection",
         default="jpn",
     )
예제 #13
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to paste into",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "-s",
         "--subject",
         help="subject to copy",
         choices=("text", "notes", "times", "all"),
         default="all",
     )
예제 #14
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to process",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "-s",
         "--style",
         help="how to sort the subtitles",
         type=SortStyle,
         choices=list(SortStyle),
         default=SortStyle.START,
     )
예제 #15
0
def test_get_all_indexes(
    expr: str,
    sub_count: int,
    sub_selection: T.Union[T.List[int], T.Any],
    current_pts: T.Union[int, T.Any],
    expected_indexes: T.Union[T.List[int], T.Type[CommandError]],
) -> None:
    """Test that parsing various inputs returns expected subtitle indexes.

    :param expr: input expression to parse
    :param sub_count: how many subtitles to simulate
    :param sub_selection: current subtitle selection indexes to simulate
    :param current_pts: current video PTS to simulate
    :param expected_indexes: expected selection indexes
    """
    api = Mock()
    api.playback.current_pts = current_pts
    api.subs.events = [Mock() for _ in range(sub_count)]
    for i, event in enumerate(api.subs.events):
        event.index = i
        event.num = i + 1
        event.prev = api.subs.events[i - 1] if i > 0 else None
        event.start = i * 100
        event.end = i * 100 + 50
        try:
            event.next = api.subs.events[i + 1]
        except LookupError:
            event.next = None
    if sub_selection is not Ellipsis:
        api.subs.selected_indexes = sub_selection
        api.subs.selected_events = [
            api.subs.events[idx] for idx in sub_selection
        ]
    else:
        api.subs.selected_indexes = []
        api.subs.selected_events = []

    sub_selection = SubtitlesSelection(api, expr)

    actual_indexes: T.Union[T.List[int], T.Type[CommandError]] = []
    try:
        actual_indexes = asyncio.get_event_loop().run_until_complete(
            sub_selection.get_all_indexes())
    except CommandError as ex:
        actual_indexes = type(ex)

    assert actual_indexes == expected_indexes
예제 #16
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to merge",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "--concat",
         "--concatenate",
         help=(
             "merge the subtitles text "
             "(otherwise keep only the first subtitle)"
         ),
         action="store_true",
     )
예제 #17
0
    def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "-t",
            "--target",
            help="subtitles to change",
            type=lambda value: SubtitlesSelection(api, value),
            default="selected",
        )

        parser.add_argument("--text", help="new subtitles text")
        parser.add_argument("--note", help="new subtitles note")
        parser.add_argument("--actor", help="new subtitles actor")
        parser.add_argument("--style", help="new subtitles style")
        parser.add_argument(
            "--comment",
            action="store_true",
            help="mark subtitles as a comment",
        )
        parser.add_argument(
            "--no-comment",
            action="store_true",
            help="mark subtitles as a non-comment",
        )
        parser.add_argument("--layer", help="new subtitles layer", type=int)

        parser.add_argument(
            "-s",
            "--start",
            help="new subtitles start",
            type=lambda value: Pts(api, value),
        )
        parser.add_argument(
            "-e",
            "--end",
            help="new subtitles end",
            type=lambda value: Pts(api, value),
        )
        parser.add_argument(
            "--no-align",
            help="don't realign subtitles to video frames",
            action="store_true",
        )
예제 #18
0
    def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "-t",
            "--target",
            help="subtitles to split",
            type=lambda value: SubtitlesSelection(api, value),
            default="selected",
        )

        parser.add_argument(
            "--no-align",
            help="don't align split position to video frames",
            action="store_true",
        )

        parser.add_argument(
            "-p",
            "--position",
            help="position to split the subtitles at",
            type=lambda value: Pts(api, value),
        )
예제 #19
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-t",
         "--target",
         help="subtitles to merge",
         type=lambda value: SubtitlesSelection(api, value),
         default="selected",
     )
     parser.add_argument(
         "--concat",
         "--concatenate",
         help=("merge the subtitles text and notes "
               "(otherwise keep only the first subtitle)"),
         action="store_true",
     )
     parser.add_argument(
         "--separator",
         help=("separator to merge the text with"),
         type=SubtitlesMergeSeparator,
         choices=list(SubtitlesMergeSeparator),
         default=SubtitlesMergeSeparator.NEWLINE,
     )
예제 #20
0
    def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "-t",
            "--target",
            help="subtitles to process",
            type=lambda value: SubtitlesSelection(api, value),
            default="selected",
        )

        parser.add_argument(
            "--smart-quotes",
            help="replace plain quotation marks with smart ones",
            action="store_true",
        )

        parser.add_argument(
            "--opening-quotation-mark",
            default="\N{LEFT DOUBLE QUOTATION MARK}",
        )
        parser.add_argument(
            "--closing-quotation-mark",
            default="\N{RIGHT DOUBLE QUOTATION MARK}",
        )
예제 #21
0
    def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "-o",
            "--origin",
            help="where to paste the subtitles",
            type=lambda value: SubtitlesSelection(api, value),
            default="selected",
        )

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            "--before",
            dest="dir",
            action="store_const",
            const="before",
            help="paste before origin",
        )
        group.add_argument(
            "--after",
            dest="dir",
            action="store_const",
            const="after",
            help="paste after origin",
        )
예제 #22
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "target",
         help="subtitles to select",
         type=lambda value: SubtitlesSelection(api, value),
     )