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
b9eedbf8
Verified
Commit
b9eedbf8
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Ensure subsonic dates are formatted properly
parent
144713fd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/subsonic/serializers.py
+17
-6
17 additions, 6 deletions
api/funkwhale_api/subsonic/serializers.py
api/tests/subsonic/test_serializers.py
+19
-7
19 additions, 7 deletions
api/tests/subsonic/test_serializers.py
with
36 additions
and
13 deletions
api/funkwhale_api/subsonic/serializers.py
+
17
−
6
View file @
b9eedbf8
...
...
@@ -8,6 +8,17 @@ from funkwhale_api.music import models as music_models
from
funkwhale_api.music
import
utils
as
music_utils
def
to_subsonic_date
(
date
):
"""
Subsonic expects this kind of date format: 2012-04-17T19:55:49.000Z
"""
if
not
date
:
return
return
date
.
strftime
(
"
%Y-%m-%dT%H:%M:%S.000Z
"
)
def
get_artist_data
(
artist_values
):
return
{
"
id
"
:
artist_values
[
"
id
"
],
...
...
@@ -52,7 +63,7 @@ class GetArtistSerializer(serializers.Serializer):
"
artistId
"
:
artist
.
id
,
"
name
"
:
album
.
title
,
"
artist
"
:
artist
.
name
,
"
created
"
:
album
.
creation_date
,
"
created
"
:
to_subsonic_date
(
album
.
creation_date
)
,
"
songCount
"
:
len
(
album
.
tracks
.
all
()),
}
if
album
.
cover
:
...
...
@@ -82,7 +93,7 @@ def get_track_data(album, track, upload):
),
"
suffix
"
:
upload
.
extension
or
""
,
"
duration
"
:
upload
.
duration
or
0
,
"
created
"
:
track
.
creation_date
,
"
created
"
:
to_subsonic_date
(
track
.
creation_date
)
,
"
albumId
"
:
album
.
pk
,
"
artistId
"
:
album
.
artist
.
pk
,
"
type
"
:
"
music
"
,
...
...
@@ -104,7 +115,7 @@ def get_album2_data(album):
"
artistId
"
:
album
.
artist
.
id
,
"
name
"
:
album
.
title
,
"
artist
"
:
album
.
artist
.
name
,
"
created
"
:
album
.
creation_date
,
"
created
"
:
to_subsonic_date
(
album
.
creation_date
)
,
}
if
album
.
cover
:
payload
[
"
coverArt
"
]
=
"
al-{}
"
.
format
(
album
.
id
)
...
...
@@ -162,7 +173,7 @@ def get_starred_tracks_data(favorites):
except
IndexError
:
continue
td
=
get_track_data
(
t
.
album
,
t
,
uploads
)
td
[
"
starred
"
]
=
by_track_id
[
t
.
pk
].
creation_date
td
[
"
starred
"
]
=
to_subsonic_date
(
by_track_id
[
t
.
pk
].
creation_date
)
data
.
append
(
td
)
return
data
...
...
@@ -179,7 +190,7 @@ def get_playlist_data(playlist):
"
public
"
:
"
false
"
,
"
songCount
"
:
playlist
.
_tracks_count
,
"
duration
"
:
0
,
"
created
"
:
playlist
.
creation_date
,
"
created
"
:
to_subsonic_date
(
playlist
.
creation_date
)
,
}
...
...
@@ -221,7 +232,7 @@ def get_music_directory_data(artist):
"
contentType
"
:
upload
.
mimetype
,
"
suffix
"
:
upload
.
extension
or
""
,
"
duration
"
:
upload
.
duration
or
0
,
"
created
"
:
track
.
creation_date
,
"
created
"
:
to_subsonic_date
(
track
.
creation_date
)
,
"
albumId
"
:
album
.
pk
,
"
artistId
"
:
artist
.
pk
,
"
parent
"
:
artist
.
id
,
...
...
This diff is collapsed.
Click to expand it.
api/tests/subsonic/test_serializers.py
+
19
−
7
View file @
b9eedbf8
import
datetime
import
pytest
from
funkwhale_api.music
import
models
as
music_models
from
funkwhale_api.subsonic
import
serializers
@pytest.mark.parametrize
(
"
date, expected
"
,
[
(
datetime
.
datetime
(
2017
,
1
,
12
,
9
,
53
,
12
,
1890
),
"
2017-01-12T09:53:12.000Z
"
),
(
None
,
None
),
],
)
def
test_to_subsonic_date
(
date
,
expected
):
assert
serializers
.
to_subsonic_date
(
date
)
==
expected
def
test_get_artists_serializer
(
factories
):
artist1
=
factories
[
"
music.Artist
"
](
name
=
"
eliot
"
)
artist2
=
factories
[
"
music.Artist
"
](
name
=
"
Ellena
"
)
...
...
@@ -54,7 +66,7 @@ def test_get_artist_serializer(factories):
"
name
"
:
album
.
title
,
"
artist
"
:
artist
.
name
,
"
songCount
"
:
len
(
tracks
),
"
created
"
:
album
.
creation_date
,
"
created
"
:
serializers
.
to_subsonic_date
(
album
.
creation_date
)
,
"
year
"
:
album
.
release_date
.
year
,
}
],
...
...
@@ -96,7 +108,7 @@ def test_get_album_serializer(factories):
"
name
"
:
album
.
title
,
"
artist
"
:
artist
.
name
,
"
songCount
"
:
1
,
"
created
"
:
album
.
creation_date
,
"
created
"
:
serializers
.
to_subsonic_date
(
album
.
creation_date
)
,
"
year
"
:
album
.
release_date
.
year
,
"
coverArt
"
:
"
al-{}
"
.
format
(
album
.
id
),
"
song
"
:
[
...
...
@@ -115,7 +127,7 @@ def test_get_album_serializer(factories):
"
bitrate
"
:
42
,
"
duration
"
:
43
,
"
size
"
:
44
,
"
created
"
:
track
.
creation_date
,
"
created
"
:
serializers
.
to_subsonic_date
(
track
.
creation_date
)
,
"
albumId
"
:
album
.
pk
,
"
artistId
"
:
artist
.
pk
,
"
type
"
:
"
music
"
,
...
...
@@ -133,7 +145,7 @@ def test_starred_tracks2_serializer(factories):
upload
=
factories
[
"
music.Upload
"
](
track
=
track
)
favorite
=
factories
[
"
favorites.TrackFavorite
"
](
track
=
track
)
expected
=
[
serializers
.
get_track_data
(
album
,
track
,
upload
)]
expected
[
0
][
"
starred
"
]
=
favorite
.
creation_date
expected
[
0
][
"
starred
"
]
=
serializers
.
to_subsonic_date
(
favorite
.
creation_date
)
data
=
serializers
.
get_starred_tracks_data
([
favorite
])
assert
data
==
expected
...
...
@@ -162,7 +174,7 @@ def test_playlist_serializer(factories):
"
public
"
:
"
false
"
,
"
songCount
"
:
1
,
"
duration
"
:
0
,
"
created
"
:
playlist
.
creation_date
,
"
created
"
:
serializers
.
to_subsonic_date
(
playlist
.
creation_date
)
,
}
qs
=
playlist
.
__class__
.
objects
.
with_tracks_count
()
data
=
serializers
.
get_playlist_data
(
qs
.
first
())
...
...
@@ -181,7 +193,7 @@ def test_playlist_detail_serializer(factories):
"
public
"
:
"
false
"
,
"
songCount
"
:
1
,
"
duration
"
:
0
,
"
created
"
:
playlist
.
creation_date
,
"
created
"
:
serializers
.
to_subsonic_date
(
playlist
.
creation_date
)
,
"
entry
"
:
[
serializers
.
get_track_data
(
plt
.
track
.
album
,
plt
.
track
,
upload
)],
}
qs
=
playlist
.
__class__
.
objects
.
with_tracks_count
()
...
...
@@ -213,7 +225,7 @@ def test_directory_serializer_artist(factories):
"
bitrate
"
:
42
,
"
duration
"
:
43
,
"
size
"
:
44
,
"
created
"
:
track
.
creation_date
,
"
created
"
:
serializers
.
to_subsonic_date
(
track
.
creation_date
)
,
"
albumId
"
:
album
.
pk
,
"
artistId
"
:
artist
.
pk
,
"
parent
"
:
artist
.
pk
,
...
...
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