def _decode_ts_file(key_val: bytes, decode_hash: dict, ts_num: int, game_id: int) -> None: command = ('openssl enc -aes-128-cbc -in "' + f"{game_id}/{ts_num}.ts" + '" -out "' + f"{game_id}/{ts_num}.ts.dec" + '" -d -K ' + key_val.decode() + " -iv " + decode_hash["iv"]) call_subprocess_and_raise_on_error(command, DecodeError)
def _shorten_video(game_id: int) -> None: tprint("Shortening download to 100 files") command = "mv %s/download_file.txt %s/download_file_orig.txt;" % ( game_id, game_id, ) command += ("head -100 %s/download_file_orig.txt > %s/download_file.txt;" % (game_id, game_id)) command += "rm -f %s/download_file_orig.txt;" % game_id call_subprocess_and_raise_on_error(command)
def get_video_length(input_file: str) -> int: command = (f"ffprobe -v error -show_entries format=duration -of " f"default=noprint_wrappers=1:nokey=1 {input_file}") proc_out: List[bytes] = call_subprocess_and_raise_on_error(command) return int(proc_out[0].split(b".")[0])
def _download_page_with_aria2(game_id: int, filename: str, url: str): download_options = _get_download_options(game_id) command = "aria2c -o " + filename + download_options + url call_subprocess_and_raise_on_error(command)
def test_call_subp_and_raise_custom_error(mocker, mocked_call_subprocess): mocked_call_subprocess().returncode = 1 with pytest.raises(DecodeError): call_subprocess_and_raise_on_error("boo", DecodeError)
def test_call_subp_and_raise_default_error(mocker, mocked_call_subprocess): mocked_call_subprocess().returncode = 1 with pytest.raises(ExternalProgramError): call_subprocess_and_raise_on_error("boo")
def test_call_subp_and_raise(mocker, mocked_call_subprocess): mocked_call_subprocess().returncode = 0 call_subprocess_and_raise_on_error("foo")
def concat_video(concat_list_path: str, output_file: str, extra_args: str = "") -> None: command = (f"ffmpeg -y -nostats -loglevel 0 -f concat -safe 0 -i " f"{concat_list_path} -c copy {extra_args} {output_file}") call_subprocess_and_raise_on_error(command)
def show_video_streams(input_file: str) -> List[bytes]: command: str = (f"ffprobe -i {input_file} -show_streams" f" -select_streams v -loglevel error") proc_out: List[bytes] = call_subprocess_and_raise_on_error(command) return proc_out
def cut_video(input_file: str, output_file: str, length: int) -> None: command = (f"ffmpeg -ss 0 -i {input_file} -t {length} " f"-c copy {output_file}") call_subprocess_and_raise_on_error(command)