mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 20:11:58 +02:00
Ensure subsonic dates are formatted properly
This commit is contained in:
parent
144713fdc1
commit
b9eedbf89f
2 changed files with 36 additions and 13 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue