Skip to content

Commit

Permalink
Only check for non SND files
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Jul 26, 2024
1 parent 1e477bf commit 5d83477
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 5 additions & 5 deletions audiofile/core/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,21 @@ def has_video(file: str) -> bool:
FileNotFoundError: if mediainfo binary is needed,
but cannot be found
RuntimeError: if ``file`` is missing
and does not end with ``"wav"``, ``"flac"``, ``"mp3"``, ``"ogg"``
Examples:
>>> has_video("stereo.wav")
False
"""
file = audeer.path(file)
if not os.path.exists(file):
raise RuntimeError(f"{file} does not exist.")

if file_extension(file) in SNDFORMATS:
return False
else:
try:
cmd = ["mediainfo", "--Inform=Video;%Format%", file]
path = audeer.path(file)
if not os.path.exists(path):
raise RuntimeError(f"'{file}' does not exist.")
cmd = ["mediainfo", "--Inform=Video;%Format%", path]
video_format = run(cmd)
if len(video_format) > 0:
return True
Expand Down
18 changes: 16 additions & 2 deletions tests/test_audiofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,28 @@ def test_missing_file(tmpdir, ext):
af.duration(missing_file)
with pytest.raises(expected_error):
af.duration(missing_file, sloppy=True)
with pytest.raises(expected_error):
af.has_video(missing_file)
# Convert
with pytest.raises(expected_error):
converted_file = str(tmpdir.join("signal-converted.wav"))
af.convert_to_wav(missing_file, converted_file)


@pytest.mark.parametrize(
"file, expected_error, expected_error_message",
[
("missing_file.bin", RuntimeError, "'missing_file.bin' does not exist"),
("missing_file.mp4", RuntimeError, "'missing_file.mp4' does not exist"),
("missing_file.wav", None, None),
],
)
def test_missing_file_has_video(file, expected_error, expected_error_message):
if expected_error is not None:
with pytest.raises(expected_error, match=expected_error_message):
af.has_video(file)
else:
assert af.has_video(file) is False


@pytest.mark.parametrize(
"non_audio_file",
("bin", "mp4", "wav"),
Expand Down

0 comments on commit 5d83477

Please sign in to comment.