Fix #898: Pickup folder.png and folder.jpg files for cover art when importing from CLI
This commit is contained in:
parent
3a9f2cde37
commit
3204dfd342
|
@ -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):
|
def get_cover_from_fs(dir_path):
|
||||||
if os.path.exists(dir_path):
|
if os.path.exists(dir_path):
|
||||||
for e, m in IMAGE_TYPES:
|
for name in FOLDER_IMAGE_NAMES:
|
||||||
cover_path = os.path.join(dir_path, "cover.{}".format(e))
|
for e, m in IMAGE_TYPES:
|
||||||
if not os.path.exists(cover_path):
|
cover_path = os.path.join(dir_path, "{}.{}".format(name, e))
|
||||||
logger.debug("Cover %s does not exists", cover_path)
|
if not os.path.exists(cover_path):
|
||||||
continue
|
logger.debug("Cover %s does not exists", cover_path)
|
||||||
with open(cover_path, "rb") as c:
|
continue
|
||||||
logger.info("Found cover at %s", cover_path)
|
with open(cover_path, "rb") as c:
|
||||||
return {"mimetype": m, "content": c.read()}
|
logger.info("Found cover at %s", cover_path)
|
||||||
|
return {"mimetype": m, "content": c.read()}
|
||||||
|
|
||||||
|
|
||||||
@celery.app.task(name="music.start_library_scan")
|
@celery.app.task(name="music.start_library_scan")
|
||||||
|
|
|
@ -843,3 +843,34 @@ def test_update_library_entity(factories, mocker):
|
||||||
|
|
||||||
artist.refresh_from_db()
|
artist.refresh_from_db()
|
||||||
assert artist.name == "Hello"
|
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
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Pickup folder.png and folder.jpg files for cover art when importing from CLI (#898)
|
Loading…
Reference in New Issue