Esempio n. 1
0
def test_no_eng_audio_is_skipped():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("dts")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3])

    assert file_processor.state == streamix.FileState.Skip
Esempio n. 2
0
def test_first_audio_eng_and_safe_codec_is_skipped():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac", language="eng")
    s3 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3])

    assert file_processor.state == streamix.FileState.Skip
Esempio n. 3
0
def test_other_stream_eng_is_convert():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("abc", language="eng")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3])

    assert file_processor.state == streamix.FileState.Convert
Esempio n. 4
0
def test_other_stream_eng_is_convert_uses_priority():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("pcm_dvd", language="eng")
    s4 = testhelper.build_audio_stream("dts", language="eng")
    s5 = testhelper.build_audio_stream("pcm_dvd", language="eng")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4, s5])

    assert file_processor.state == streamix.FileState.Convert
Esempio n. 5
0
def test_remap_moves_safe_eng_to_first():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("aac", language="eng")
    s4 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    stream_order = file_processor._remap_stream_order()

    assert stream_order == [s1, s3, s2, s4]
Esempio n. 6
0
def test_convert_selects_eng():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("abc", language="eng")
    s4 = testhelper.build_audio_stream("abc")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    selected_stream = file_processor._select_stream().raw

    assert selected_stream == s3
Esempio n. 7
0
def test_remap_command_never_calls_aac():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("aac", language="eng")
    s4 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    cmd = file_processor._get_command()

    assert "aac" not in cmd
Esempio n. 8
0
def test_convert_selects_by_priority():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("pcm_dvd", language="eng")
    s4 = testhelper.build_audio_stream("dts", language="eng")
    s5 = testhelper.build_audio_stream("pcm_dvd", language="eng")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4, s5])

    # noinspection PyProtectedMember
    selected_stream = file_processor._select_stream().raw

    assert selected_stream == s4
Esempio n. 9
0
def test_convert_uses_bitrate():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("abc", language="eng", bitrate=1)
    s4 = testhelper.build_audio_stream("abc", language="eng", bitrate=10)
    s5 = testhelper.build_audio_stream("abc", language="eng", bitrate=2)
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4, s5])

    # noinspection PyProtectedMember
    selected_stream = file_processor._select_stream().raw

    assert selected_stream == s4
Esempio n. 10
0
def test_subprocess_call(mock_rename):
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2])

    with unittest.mock.patch("streamix.logger") as mock_logger:
        with unittest.mock.patch("streamix.FileProcessor._get_command") as mock_get_command:
            mock_get_command.return_value = "ls -la"
            file_processor.run()

        assert mock_logger.info.called
        info_args = mock_logger.info.call_args
        assert info_args[0][0].startswith("Successfully re-encoded:")
Esempio n. 11
0
def test_convert_command_uses_default_bitrate_if_lower():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("abc", language="eng", bitrate=100)
    s4 = testhelper.build_audio_stream("abc")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    cmd = file_processor._get_command()

    tokens = cmd.split()
    encode_token_index = next(i for i, t in enumerate(tokens) if t.startswith("-b:"))
    assert tokens[encode_token_index + 1] == str(320000)
Esempio n. 12
0
def test_convert_command_leaves_original_stream_map_params():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("abc", language="eng")
    s4 = testhelper.build_audio_stream("abc")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    cmd = file_processor._get_command()

    tokens = cmd.split()
    actual_stream_map = [int(tokens[i+1][2:]) for i, t in enumerate(tokens) if t.startswith("-map")]

    assert actual_stream_map == [0, 2, 1, 2, 3]
Esempio n. 13
0
def test_convert_uses_bitrate_after_priority():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("pcm_dvd", language="eng", bitrate=1)
    s4 = testhelper.build_audio_stream("dts", language="eng", bitrate=10)
    s5 = testhelper.build_audio_stream("pcm_dvd", language="eng", bitrate=2)
    s6 = testhelper.build_audio_stream("dts", language="eng", bitrate=100)
    s7 = testhelper.build_audio_stream("pcm_dvd", language="eng", bitrate=1000)
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4, s5, s6, s7])

    # noinspection PyProtectedMember
    selected_stream = file_processor._select_stream().raw

    assert selected_stream == s6
Esempio n. 14
0
def test_convert_command_maps_streams_in_codec_params():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("abc", language="eng")
    s4 = testhelper.build_audio_stream("abc")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    cmd = file_processor._get_command()

    tokens = cmd.split()
    actual_codec_map = [int(t[3:]) for t in tokens if t.startswith("-c:")]

    # expect the codec map to be sequential
    assert actual_codec_map == [0, 1, 2, 3, 4]
Esempio n. 15
0
def test_remap_command_only_copies():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("aac", language="eng")
    s4 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    cmd = file_processor._get_command()

    tokens = cmd.split()
    for i, t in enumerate(tokens):
        if t.startswith("-c"):
            # the command following the -c must be copy
            assert tokens[i+1] == "copy"
Esempio n. 16
0
def test_remap_command_respects_stream_order():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    s3 = testhelper.build_audio_stream("aac", language="eng")
    s4 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2, s3, s4])

    # noinspection PyProtectedMember
    stream_order = file_processor._remap_stream_order()
    # noinspection PyProtectedMember
    cmd = file_processor._get_command()

    stream_index = 0
    tokens = cmd.split()
    for i, t in enumerate(tokens):
        if t.startswith("-map"):
            # the command following the -map should match the stream order (using the index)
            assert tokens[i+1] == "0:{0}".format(stream_order[stream_index]["index"])
            stream_index += 1
Esempio n. 17
0
def test_file_with_only_aac_stream_is_skipped():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2])

    assert file_processor.state == streamix.FileState.Skip
Esempio n. 18
0
def test_file_with_wrong_ext_is_ignored():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("aac")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2], filename="skipped.file")

    assert file_processor.state == streamix.FileState.Ignore
Esempio n. 19
0
def test_file_with_unknown_codec_is_skipped():
    s1 = testhelper.build_video_stream()
    s2 = testhelper.build_audio_stream("crazy codec")
    file_processor = testhelper.build_file_processor_for_streams([s1, s2])

    assert file_processor.state == streamix.FileState.Skip