Ejemplo n.º 1
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "--start",
         help="where the sample should start",
         type=lambda value: Pts(api, value),
         default="a.s",
     )
     parser.add_argument(
         "--end",
         help="where the sample should end",
         type=lambda value: Pts(api, value),
         default="a.e",
     )
     parser.add_argument(
         "-p",
         "--path",
         help="path to save the sample to",
         type=lambda value: FancyPath(api, value),
         default="",
     )
     parser.add_argument(
         "-i",
         "--include-subs",
         help='whether to "burn" subtitles into the video stream',
         action="store_true",
     )
     parser.add_argument(
         "--crf",
         help="constant rate factor parameter for ffmpeg (default: 20)",
         type=int,
         default=20,
     )
Ejemplo n.º 2
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,
     )
Ejemplo n.º 3
0
def test_min_max() -> None:
    """Test min and max possible PTS magic strings."""
    api = Mock()
    api.playback.max_pts = 999

    min_pts = Pts(api, "min")
    max_pts = Pts(api, "max")

    _assert_pts_value(min_pts, 0)
    _assert_pts_value(max_pts, 999)
Ejemplo n.º 4
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-s",
         "--start",
         help="start of region to play",
         type=lambda value: Pts(api, value),
         default="cf",
     )
     parser.add_argument(
         "-e",
         "--end",
         help="end of region to play",
         type=lambda value: Pts(api, value),
     )
Ejemplo n.º 5
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "--pts",
         help="which frame to make screenshot of",
         type=lambda value: Pts(api, value),
         default="cf",
     )
     parser.add_argument(
         "-p",
         "--path",
         help="path to save the screenshot to",
         type=lambda value: FancyPath(api, value),
         default="",
     )
     parser.add_argument(
         "-i",
         "--include-subs",
         help='whether to "burn" the subtitles into the screenshot',
         action="store_true",
     )
     parser.add_argument(
         "--width",
         help="width of the screenshot (by default, original video width)",
         type=int,
     )
     parser.add_argument(
         "--height",
         help=(
             "height of the screenshot (by default, original video height)"
         ),
         type=int,
     )
     parser.epilog = ("If only either of width or height is given, "
                      "the command tries to maintain aspect ratio.")
Ejemplo n.º 6
0
def test_default_subtitle_duration() -> None:
    """Test default subtitle duration magic string."""
    api = Mock()
    api.cfg.opt = {"subs": {"default_duration": 123}}
    pts = Pts(api, "dsd")

    _assert_pts_value(pts, 123)
Ejemplo n.º 7
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-p",
         "--pos",
         help="where to seek",
         type=lambda value: Pts(api, value),
         required=True,
     )
     parser.add_argument(
         "--precise",
         help=(
             "whether to use precise seeking at the expense of performance"
         ),
         action="store_true",
     )
     parser.add_argument(
         "-P",
         "--pause",
         help="pause after seeking",
         action="store_true",
     )
     parser.add_argument(
         "-U",
         "--unpause",
         help="unpause after seeking",
         dest="pause",
         action="store_false",
     )
Ejemplo n.º 8
0
def test_frames(
    expr: str,
    frame_times: T.List[int],
    cur_frame_idx: T.Any,
    keyframe_indexes: T.List[int],
    expected_value: T.Union[int, T.Type[CommandError]],
) -> None:
    """Test frame and keyframe arithmetic.

    :param expr: input expression to parse
    :param frame_times: frame PTS to simulate
    :param cur_frame_idx: current video frame index to simulate
    :param keyframe_indexes: which frames are keyframes to simulate
    :param expected_value: expected PTS
    """
    api = Mock()
    api.video.current_stream.timecodes = frame_times
    api.video.current_stream.keyframes = keyframe_indexes
    if cur_frame_idx is Ellipsis:
        api.playback.current_pts = 0
    else:
        api.playback.current_pts = frame_times[cur_frame_idx]
    pts = Pts(api, expr)

    _assert_pts_value(pts, expected_value)
Ejemplo n.º 9
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-s",
         "--start",
         help="new start of the selection",
         type=lambda value: Pts(api, value),
     )
     parser.add_argument(
         "-e",
         "--end",
         help="new end of the selection",
         type=lambda value: Pts(api, value),
     )
     parser.add_argument(
         "--no-align",
         help="don't realign selection to video frames",
         action="store_true",
     )
Ejemplo n.º 10
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",
        )
Ejemplo n.º 11
0
def test_audio_view(expr: str, view: T.Tuple[int, int],
                    expected_value: int) -> None:
    """Test spectrogram viewport magic strings.

    :param expr: input expression to parse
    :param view: audio view to simulate
    :param expected_value: expected PTS
    """
    api = Mock()
    api.audio.view.view_start = view[0]
    api.audio.view.view_end = view[1]
    pts = Pts(api, expr)
    _assert_pts_value(pts, expected_value)
Ejemplo n.º 12
0
 def decorate_parser(api: Api, parser: argparse.ArgumentParser) -> None:
     parser.add_argument(
         "-s",
         "--start",
         help="start of the audio sample",
         type=lambda value: Pts(api, value),
         default="a.s",
     )
     parser.add_argument(
         "-e",
         "--end",
         help="end of the audio sample",
         type=lambda value: Pts(api, value),
         default="a.e",
     )
     parser.add_argument(
         "-p",
         "--path",
         help="path to save the sample to",
         type=lambda value: FancyPath(api, value),
         default="",
     )
Ejemplo n.º 13
0
def _assert_pts_value(
    pts: Pts,
    expected_value: T.Union[int, T.Type[CommandError]],
    origin: T.Optional[int] = None,
) -> None:
    actual_value: T.Union[int, T.Type[CommandError]] = 0
    try:
        actual_value = asyncio.get_event_loop().run_until_complete(
            pts.get(origin=origin))
    except CommandError as ex:
        actual_value = type(ex)

    assert actual_value == expected_value
Ejemplo n.º 14
0
def test_basic_arithmetic(
    expr: str,
    origin: T.Optional[int],
    expected_value: T.Union[int, T.Type[CommandError]],
) -> None:
    """Test time arithemtic.

    :param expr: input expression to parse
    :param origin: optional origin to parse against
    :param expected_value: expected PTS
    """
    api = Mock()
    pts = Pts(api, expr)

    _assert_pts_value(pts, expected_value, origin)
Ejemplo n.º 15
0
    async def _get_delta(self, subs: T.List[AssEvent],
                         main_window: QtWidgets.QMainWindow) -> Pts:
        ret = await time_jump_dialog(
            main_window,
            absolute_label="Time to move to:",
            relative_label="Time to add:",
            relative_checked=True,
        )
        if ret is None:
            raise CommandCanceled

        delta, is_relative = ret
        if not is_relative and subs:
            delta -= subs[0].start

        return Pts(self.api, f"{delta:+d}ms")
Ejemplo n.º 16
0
def test_audio_selection(
    expr: str,
    selection: T.Tuple[int, int],
    expected_value: T.Union[int, T.Type[CommandError]],
) -> None:
    """Test audio selection magic strings.

    :param expr: input expression to parse
    :param selection: audio selection to simulate
    :param expected_value: expected PTS
    """
    api = Mock()
    api.audio.view.selection_start = selection[0]
    api.audio.view.selection_end = selection[1]
    pts = Pts(api, expr)
    _assert_pts_value(pts, expected_value)
Ejemplo n.º 17
0
def test_subtitles(
    expr: str,
    sub_times: T.List[T.Tuple[int, int]],
    sub_selection: T.List[int],
    expected_value: int,
) -> None:
    """Test first, last, current, previous, next and selected subtitle
    boundaries.

    :param expr: input expression to parse
    :param sub_times: subtitle PTS to simulate
    :param sub_selection: current subtitle selection indexes to simulate
    :param expected_value: expected PTS
    """
    api = Mock()
    api.subs = _mock_subs_api(sub_times, sub_selection)

    pts = Pts(api, expr)

    _assert_pts_value(pts, expected_value)
Ejemplo n.º 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),
        )