Fix #214: Do not crash on flac import if musicbrainz tags are missing

This commit is contained in:
Eliot Berriot 2018-05-22 23:53:45 +02:00
parent 54008aa37c
commit 01ea6562a6
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
3 changed files with 13 additions and 1 deletions

View File

@ -30,7 +30,7 @@ def get_id3_tag(f, k):
def get_flac_tag(f, k):
try:
return f.get(k)[0]
return f.get(k, [])[0]
except (KeyError, IndexError):
raise TagNotFound(k)
@ -158,6 +158,9 @@ CONF = {
'musicbrainz_recordingid': {
'field': 'musicbrainz_trackid'
},
'test': {
'field': 'test'
},
}
},
}

View File

@ -57,3 +57,11 @@ def test_can_get_metadata_from_flac_file(field, value):
data = metadata.Metadata(path)
assert data.get(field) == value
def test_can_get_metadata_from_flac_file_not_crash_if_empty():
path = os.path.join(DATA_DIR, 'sample.flac')
data = metadata.Metadata(path)
with pytest.raises(metadata.TagNotFound):
data.get('test')

View File

@ -0,0 +1 @@
Do not crash on flac import if musicbrainz tags are missing (#214)