Skip to content
Snippets Groups Projects
Commit 8d2529f4 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch 'flac-support' into 'develop'

Fix #157: Can now import and play flac files

Closes #157

See merge request funkwhale/funkwhale!192
parents 2f44dd0e ce92747d
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,13 @@ def get_id3_tag(f, k):
raise TagNotFound(k)
def get_flac_tag(f, k):
try:
return f.get(k)[0]
except (KeyError, IndexError):
raise TagNotFound(k)
def get_mp3_recording_id(f, k):
try:
return [
......@@ -121,7 +128,38 @@ CONF = {
'getter': get_mp3_recording_id,
},
}
}
},
'FLAC': {
'getter': get_flac_tag,
'fields': {
'track_number': {
'field': 'tracknumber',
'to_application': convert_track_number
},
'title': {
'field': 'title'
},
'artist': {
'field': 'artist'
},
'album': {
'field': 'album'
},
'date': {
'field': 'date',
'to_application': lambda v: arrow.get(str(v)).date()
},
'musicbrainz_albumid': {
'field': 'musicbrainz_albumid'
},
'musicbrainz_artistid': {
'field': 'musicbrainz_artistid'
},
'musicbrainz_recordingid': {
'field': 'musicbrainz_trackid'
},
}
},
}
......
......@@ -66,6 +66,7 @@ def compute_status(jobs):
AUDIO_EXTENSIONS_AND_MIMETYPE = [
('ogg', 'audio/ogg'),
('mp3', 'audio/mpeg'),
('flac', 'audio/flac'),
]
EXTENSION_TO_MIMETYPE = {ext: mt for ext, mt in AUDIO_EXTENSIONS_AND_MIMETYPE}
......
File added
......@@ -40,3 +40,20 @@ def test_can_get_metadata_from_id3_mp3_file(field, value):
data = metadata.Metadata(path)
assert data.get(field) == value
@pytest.mark.parametrize('field,value', [
('title', '999,999'),
('artist', 'Nine Inch Nails'),
('album', 'The Slip'),
('date', datetime.date(2008, 5, 5)),
('track_number', 1),
('musicbrainz_albumid', uuid.UUID('12b57d46-a192-499e-a91f-7da66790a1c1')),
('musicbrainz_recordingid', uuid.UUID('30f3f33e-8d0c-4e69-8539-cbd701d18f28')),
('musicbrainz_artistid', uuid.UUID('b7ffd2af-418f-4be2-bdd1-22f8b48613da')),
])
def test_can_get_metadata_from_flac_file(field, value):
path = os.path.join(DATA_DIR, 'sample.flac')
data = metadata.Metadata(path)
assert data.get(field) == value
Can now import and play flac files (#157)
......@@ -5,6 +5,7 @@ export default {
],
formatsMap: {
'audio/ogg': 'ogg',
'audio/mpeg': 'mp3'
'audio/mpeg': 'mp3',
'audio/flac': 'flac'
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment