Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not treating images as audio #57

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion soundconverter/gstreamer/discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,16 @@ def _analyse_file(self, sound_file):
for tag, value in sound_file.tags.items():
logger.debug(' {}: {}'.format(tag, value))

duration = info.get_duration() / Gst.SECOND
if duration == 0:
# might be an image
return

# since threads share memory, this doesn't have to be sent
# over a bus or queue, but rather can be written into the
# sound_file
sound_file.duration = info.get_duration() / Gst.SECOND
sound_file.duration = duration

sound_file.readable = True
except Exception as error:
if not isinstance(error, GLib.Error):
Expand Down
Binary file added tests/test data/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/testcases/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_single_dir_depth_input(self):
'file:https://' + urllib.parse.quote(os.path.realpath('test data/audio/strângë chàrs фズ.wav')),
'file:https://' + os.path.realpath('test%20data/empty/a'),
'file:https://' + os.path.realpath('test%20data/empty/b/c'),
'file:https://' + os.path.realpath('test%20data/image.jpg'),
'file:https://' + os.path.realpath('test%20data/a.iso'),
'file:https://' + os.path.realpath('test%20data/no%20tags/no-tags.mp3'),
'file:https://' + os.path.realpath('test%20data/no%20tags/no-tags.ogg'),
Expand All @@ -143,6 +144,7 @@ def test_single_dir_depth_input(self):
'test data/empty/',
'test data/empty/b/',
'test data/',
'test data/',
'test data/no tags/',
'test data/no tags/',
'test data/no tags/'
Expand All @@ -161,6 +163,7 @@ def test_absolute(self):
'file:https://' + urllib.parse.quote(os.path.realpath('tests/test data/audio/strângë chàrs фズ.wav')),
'file:https://' + os.path.realpath('tests/test%20data/empty/a'),
'file:https://' + os.path.realpath('tests/test%20data/empty/b/c'),
'file:https://' + os.path.realpath('tests/test%20data/image.jpg'),
'file:https://' + os.path.realpath('tests/test%20data/a.iso'),
'file:https://' + os.path.realpath('tests/test%20data/no%20tags/no-tags.mp3'),
'file:https://' + os.path.realpath('tests/test%20data/no%20tags/no-tags.ogg'),
Expand All @@ -177,6 +180,7 @@ def test_absolute(self):
'test data/empty/',
'test data/empty/b/',
'test data/',
'test data/',
'test data/no tags/',
'test data/no tags/',
'test data/no tags/'
Expand Down
26 changes: 14 additions & 12 deletions tests/testcases/discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ def test_read_tags_multiple(self):
self.assertLess(abs(sound_files[2].duration - 1.00), 0.01)

def test_not_audio(self):
c_mp3 = 'file:https://' + os.path.realpath('tests/test%20data/empty/a')
empty = 'file:https://' + os.path.realpath('tests/test%20data/empty/a')
a_iso = 'file:https://' + os.path.realpath('tests/test%20data/a.iso')
discoverer = Discoverer([SoundFile(c_mp3), SoundFile(a_iso)])
image_jpg = 'file:https://' + os.path.realpath('tests/test%20data/image.jpg')
discoverer = Discoverer([
SoundFile(empty),
SoundFile(a_iso),
SoundFile(image_jpg)
])
discoverer.set_callback(lambda _: None)
discoverer.run()

Expand All @@ -164,16 +169,13 @@ def test_not_audio(self):

done.assert_called_with(discoverer)

sound_file = discoverer.sound_files[0]
self.assertIsNone(sound_file.duration)
self.assertFalse(sound_file.readable)
self.assertEqual(len(sound_file.tags), 0)

sound_file = discoverer.sound_files[1]
self.assertEqual(is_denylisted(sound_file), '*.iso')
self.assertIsNone(sound_file.duration)
self.assertFalse(sound_file.readable)
self.assertEqual(len(sound_file.tags), 0)
self.assertEqual(len(discoverer.sound_files), 3)
for sound_file in discoverer.sound_files:
self.assertFalse(sound_file.readable)
self.assertIsNone(sound_file.duration)
self.assertEqual(len(sound_file.tags), 0)

self.assertEqual(is_denylisted(discoverer.sound_files[1]), '*.iso')


if __name__ == "__main__":
Expand Down