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

Merge branch '898-folder-jpg' into 'develop'

Fix #898: Pickup folder.png and folder.jpg files for cover art when importing from CLI

Closes #898

See merge request funkwhale/funkwhale!895
parents 1fd49e64 3204dfd3
No related branches found
No related tags found
No related merge requests found
......@@ -55,19 +55,21 @@ def update_album_cover(
)
IMAGE_TYPES = [("jpg", "image/jpeg"), ("png", "image/png")]
IMAGE_TYPES = [("jpg", "image/jpeg"), ("jpeg", "image/jpeg"), ("png", "image/png")]
FOLDER_IMAGE_NAMES = ["cover", "folder"]
def get_cover_from_fs(dir_path):
if os.path.exists(dir_path):
for e, m in IMAGE_TYPES:
cover_path = os.path.join(dir_path, "cover.{}".format(e))
if not os.path.exists(cover_path):
logger.debug("Cover %s does not exists", cover_path)
continue
with open(cover_path, "rb") as c:
logger.info("Found cover at %s", cover_path)
return {"mimetype": m, "content": c.read()}
for name in FOLDER_IMAGE_NAMES:
for e, m in IMAGE_TYPES:
cover_path = os.path.join(dir_path, "{}.{}".format(name, e))
if not os.path.exists(cover_path):
logger.debug("Cover %s does not exists", cover_path)
continue
with open(cover_path, "rb") as c:
logger.info("Found cover at %s", cover_path)
return {"mimetype": m, "content": c.read()}
@celery.app.task(name="music.start_library_scan")
......
......@@ -843,3 +843,34 @@ def test_update_library_entity(factories, mocker):
artist.refresh_from_db()
assert artist.name == "Hello"
@pytest.mark.parametrize(
"name, ext, mimetype",
[
("cover", "png", "image/png"),
("cover", "jpg", "image/jpeg"),
("cover", "jpeg", "image/jpeg"),
("folder", "png", "image/png"),
("folder", "jpg", "image/jpeg"),
("folder", "jpeg", "image/jpeg"),
],
)
def test_get_cover_from_fs(name, ext, mimetype, tmpdir):
cover_path = os.path.join(tmpdir, "{}.{}".format(name, ext))
content = "Hello"
with open(cover_path, "w") as f:
f.write(content)
expected = {"mimetype": mimetype, "content": content.encode()}
assert tasks.get_cover_from_fs(tmpdir) == expected
@pytest.mark.parametrize("name", ["cover.gif", "folder.gif"])
def test_get_cover_from_fs_ignored(name, tmpdir):
cover_path = os.path.join(tmpdir, name)
content = "Hello"
with open(cover_path, "w") as f:
f.write(content)
assert tasks.get_cover_from_fs(tmpdir) is None
Pickup folder.png and folder.jpg files for cover art when importing from CLI (#898)
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