Verified Commit 3204dfd3 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

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

parent 3a9f2cde
Pipeline #5569 passed with stages
in 4 minutes and 29 seconds
......@@ -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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment