Skip to content

Commit

Permalink
FfmpegMediaTypeError (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianisnotlan authored Oct 17, 2023
1 parent 64ea8c1 commit 6fef444
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ffmpeg_media_type/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class FfmpegMediaTypeError(Exception):
pass
5 changes: 4 additions & 1 deletion src/ffmpeg_media_type/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import shlex
import tempfile

from ..exceptions import FfmpegMediaTypeError


def call(cmds: list[str]) -> str:
# call command and return stdout

command = " ".join(shlex.quote(part) for part in cmds)
with tempfile.TemporaryDirectory() as tmpdir:
output_path = f"{tmpdir}/output.txt"
assert os.system(f"{command} > {output_path}") == 0, f"command failed: {command}"
if os.system(f"{command} > {output_path}") != 0:
raise FfmpegMediaTypeError(f"command failed: {command}")

with open(output_path) as ifile:
return ifile.read()

0 comments on commit 6fef444

Please sign in to comment.