Exposes more metadata in subsonic album endpoint (#623)
This commit is contained in:
parent
2e4354717f
commit
98b3edb06a
|
@ -1,6 +1,7 @@
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from django.db.models import Count, functions
|
from django.db.models import Count, functions
|
||||||
|
from django.db.models import Sum
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from funkwhale_api.history import models as history_models
|
from funkwhale_api.history import models as history_models
|
||||||
|
@ -147,10 +148,17 @@ def get_album2_data(album):
|
||||||
"name": album.title,
|
"name": album.title,
|
||||||
"artist": album.artist.name,
|
"artist": album.artist.name,
|
||||||
"created": to_subsonic_date(album.creation_date),
|
"created": to_subsonic_date(album.creation_date),
|
||||||
|
"duration": album.tracks.aggregate(d=Sum("uploads__duration"))["d"] or 0,
|
||||||
|
"playCount": album.tracks.aggregate(c=Sum("downloads_count"))["c"] or 0,
|
||||||
}
|
}
|
||||||
if album.attachment_cover_id:
|
if album.attachment_cover_id:
|
||||||
payload["coverArt"] = "al-{}".format(album.id)
|
payload["coverArt"] = "al-{}".format(album.id)
|
||||||
|
if album.tagged_items:
|
||||||
|
# exposes only first genre since the specification uses singular noun
|
||||||
|
first_genre = album.tagged_items.first()
|
||||||
|
payload["genre"] = first_genre.tag.name if first_genre else ""
|
||||||
|
if album.release_date:
|
||||||
|
payload["year"] = album.release_date.year
|
||||||
try:
|
try:
|
||||||
payload["songCount"] = album._tracks_count
|
payload["songCount"] = album._tracks_count
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from django.db.models.aggregates import Sum
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from funkwhale_api.music import models as music_models
|
from funkwhale_api.music import models as music_models
|
||||||
|
@ -181,6 +183,9 @@ def test_get_album_serializer(factories):
|
||||||
"created": serializers.to_subsonic_date(album.creation_date),
|
"created": serializers.to_subsonic_date(album.creation_date),
|
||||||
"year": album.release_date.year,
|
"year": album.release_date.year,
|
||||||
"coverArt": "al-{}".format(album.id),
|
"coverArt": "al-{}".format(album.id),
|
||||||
|
"genre": ", ".join([ti.tag.name for ti in album.tagged_items.all()]),
|
||||||
|
"duration": album.tracks.aggregate(d=Sum("uploads__duration"))["d"] or 0,
|
||||||
|
"playCount": album.tracks.aggregate(c=Sum("downloads_count"))["c"] or 0,
|
||||||
"song": [
|
"song": [
|
||||||
{
|
{
|
||||||
"id": track.pk,
|
"id": track.pk,
|
||||||
|
|
Loading…
Reference in New Issue