Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
funkwhale
funkwhale
Commits
3204dfd3
Verified
Commit
3204dfd3
authored
Sep 16, 2019
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/music/tasks.py
View file @
3204dfd3
...
...
@@ -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"
)
...
...
api/tests/music/test_tasks.py
View file @
3204dfd3
...
...
@@ -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
changes/changelog.d/898.enhancement
0 → 100644
View file @
3204dfd3
Pickup folder.png and folder.jpg files for cover art when importing from CLI (#898)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment