Merge branch 'other-cover-types' into 'develop'
Importer will now pick embedded images in files with OTHER type if no COVER_FRONT is present See merge request funkwhale/funkwhale!538
This commit is contained in:
commit
b575999e22
|
@ -409,8 +409,14 @@ class Metadata(object):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_picture(self, picture_type="cover_front"):
|
def get_picture(self, *picture_types):
|
||||||
ptype = getattr(mutagen.id3.PictureType, picture_type.upper())
|
if not picture_types:
|
||||||
|
raise ValueError("You need to request at least one picture type")
|
||||||
|
ptypes = [
|
||||||
|
getattr(mutagen.id3.PictureType, picture_type.upper())
|
||||||
|
for picture_type in picture_types
|
||||||
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pictures = self.get("pictures")
|
pictures = self.get("pictures")
|
||||||
except (UnsupportedTag, TagNotFound):
|
except (UnsupportedTag, TagNotFound):
|
||||||
|
@ -418,6 +424,9 @@ class Metadata(object):
|
||||||
|
|
||||||
cleaner = self._conf.get("clean_pictures", lambda v: v)
|
cleaner = self._conf.get("clean_pictures", lambda v: v)
|
||||||
pictures = cleaner(pictures)
|
pictures = cleaner(pictures)
|
||||||
for p in pictures:
|
if not pictures:
|
||||||
if p["type"] == ptype:
|
return
|
||||||
return p
|
for ptype in ptypes:
|
||||||
|
for p in pictures:
|
||||||
|
if p["type"] == ptype:
|
||||||
|
return p
|
||||||
|
|
|
@ -191,7 +191,7 @@ def process_upload(upload):
|
||||||
final_metadata = collections.ChainMap(
|
final_metadata = collections.ChainMap(
|
||||||
additional_data, import_metadata, file_metadata
|
additional_data, import_metadata, file_metadata
|
||||||
)
|
)
|
||||||
additional_data["cover_data"] = m.get_picture("cover_front")
|
additional_data["cover_data"] = m.get_picture("cover_front", "other")
|
||||||
additional_data["upload_source"] = upload.source
|
additional_data["upload_source"] = upload.source
|
||||||
track = get_track_from_import_metadata(final_metadata)
|
track = get_track_from_import_metadata(final_metadata)
|
||||||
except UploadImportError as e:
|
except UploadImportError as e:
|
||||||
|
|
|
@ -147,14 +147,16 @@ def test_can_get_metadata_from_id3_mp3_file(field, value):
|
||||||
assert data.get(field) == value
|
assert data.get(field) == value
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("name", ["test.mp3", "sample.flac", "with_cover.ogg"])
|
@pytest.mark.parametrize(
|
||||||
|
"name", ["test.mp3", "with_other_picture.mp3", "sample.flac", "with_cover.ogg"]
|
||||||
|
)
|
||||||
def test_can_get_pictures(name):
|
def test_can_get_pictures(name):
|
||||||
path = os.path.join(DATA_DIR, name)
|
path = os.path.join(DATA_DIR, name)
|
||||||
data = metadata.Metadata(path)
|
data = metadata.Metadata(path)
|
||||||
|
|
||||||
pictures = data.get("pictures")
|
pictures = data.get("pictures")
|
||||||
assert len(pictures) == 1
|
assert len(pictures) == 1
|
||||||
cover_data = data.get_picture("cover_front")
|
cover_data = data.get_picture("cover_front", "other")
|
||||||
assert cover_data["mimetype"].startswith("image/")
|
assert cover_data["mimetype"].startswith("image/")
|
||||||
assert len(cover_data["content"]) > 0
|
assert len(cover_data["content"]) > 0
|
||||||
assert type(cover_data["content"]) == bytes
|
assert type(cover_data["content"]) == bytes
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
Importer will now pick embedded images in files with OTHER type if no COVER_FRONT is present
|
Loading…
Reference in New Issue