Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mélanie Chauvel
funkwhale
Commits
cdcba85f
Commit
cdcba85f
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Importing tracks without album fails"
parent
c95c573a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/funkwhale_api/music/metadata.py
+6
-2
6 additions, 2 deletions
api/funkwhale_api/music/metadata.py
api/tests/music/test_metadata.py
+28
-0
28 additions, 0 deletions
api/tests/music/test_metadata.py
changes/changelog.d/122.enhancement
+1
-0
1 addition, 0 deletions
changes/changelog.d/122.enhancement
with
35 additions
and
2 deletions
api/funkwhale_api/music/metadata.py
+
6
−
2
View file @
cdcba85f
...
...
@@ -13,6 +13,8 @@ from rest_framework.compat import Mapping
logger
=
logging
.
getLogger
(
__name__
)
NODEFAULT
=
object
()
# default title used when imported tracks miss the `Album` tag, see #122
UNKWOWN_ALBUM
=
"
[Unknown Album]
"
class
TagNotFound
(
KeyError
):
...
...
@@ -425,9 +427,11 @@ class AlbumField(serializers.Field):
def
to_internal_value
(
self
,
data
):
try
:
title
=
data
.
get
(
"
album
"
)
title
=
data
.
get
(
"
album
"
)
or
""
except
TagNotFound
:
raise
serializers
.
ValidationError
(
"
Missing album tag
"
)
title
=
""
title
=
title
.
strip
()
or
UNKWOWN_ALBUM
final
=
{
"
title
"
:
title
,
"
release_date
"
:
data
.
get
(
"
date
"
,
None
),
...
...
This diff is collapsed.
Click to expand it.
api/tests/music/test_metadata.py
+
28
−
0
View file @
cdcba85f
...
...
@@ -539,6 +539,34 @@ def test_serializer_album_artist_missing():
assert
serializer
.
validated_data
==
expected
@pytest.mark.parametrize
(
"
data
"
,
[
# no album tag
{
"
title
"
:
"
Track
"
,
"
artist
"
:
"
Artist
"
},
# empty/null values
{
"
title
"
:
"
Track
"
,
"
artist
"
:
"
Artist
"
,
"
album
"
:
""
},
{
"
title
"
:
"
Track
"
,
"
artist
"
:
"
Artist
"
,
"
album
"
:
"
"
},
{
"
title
"
:
"
Track
"
,
"
artist
"
:
"
Artist
"
,
"
album
"
:
None
},
],
)
def
test_serializer_album_default_title_when_missing_or_empty
(
data
):
expected
=
{
"
title
"
:
"
Track
"
,
"
artists
"
:
[{
"
name
"
:
"
Artist
"
,
"
mbid
"
:
None
}],
"
album
"
:
{
"
title
"
:
metadata
.
UNKWOWN_ALBUM
,
"
mbid
"
:
None
,
"
release_date
"
:
None
,
"
artists
"
:
[],
},
"
cover_data
"
:
None
,
}
serializer
=
metadata
.
TrackMetadataSerializer
(
data
=
metadata
.
FakeMetadata
(
data
))
assert
serializer
.
is_valid
(
raise_exception
=
True
)
is
True
assert
serializer
.
validated_data
==
expected
@pytest.mark.parametrize
(
"
field_name
"
,
[
"
copyright
"
,
"
license
"
,
"
mbid
"
,
"
position
"
,
"
disc_number
"
]
)
...
...
This diff is collapsed.
Click to expand it.
changes/changelog.d/122.enhancement
0 → 100644
+
1
−
0
View file @
cdcba85f
Support for importing files with no album tag (#122)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment