[music] Add listenbrainz support
This commit is contained in:
@ -19,16 +19,28 @@ class ArtistListView(generic.ListView):
|
||||
paginate_by = 100
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
qs = (
|
||||
super()
|
||||
.get_queryset()
|
||||
.annotate(scrobble_count=Count("track__scrobble"))
|
||||
.order_by("-scrobble_count")
|
||||
)
|
||||
genre = self.request.GET.get("genre")
|
||||
if genre:
|
||||
qs = qs.filter(theaudiodb_genre=genre)
|
||||
mood = self.request.GET.get("mood")
|
||||
if mood:
|
||||
qs = qs.filter(theaudiodb_mood=mood)
|
||||
return qs.order_by("-scrobble_count")
|
||||
|
||||
def get_context_data(self, *, object_list=None, **kwargs):
|
||||
context_data = super().get_context_data(object_list=object_list, **kwargs)
|
||||
context_data["view"] = self.request.GET.get("view")
|
||||
genre = self.request.GET.get("genre")
|
||||
if genre:
|
||||
context_data["active_filter"] = f"genre: {genre}"
|
||||
mood = self.request.GET.get("mood")
|
||||
if mood:
|
||||
context_data["active_filter"] = f"mood: {mood}"
|
||||
return context_data
|
||||
|
||||
|
||||
@ -68,6 +80,29 @@ class ArtistDetailView(generic.DetailView):
|
||||
.order_by("-timestamp")[:100]
|
||||
)
|
||||
|
||||
similar = artist.similar_artists or []
|
||||
if similar:
|
||||
mbids = [sa["artist_mbid"] for sa in similar if sa.get("artist_mbid")]
|
||||
local_artists = {
|
||||
a.musicbrainz_id: a
|
||||
for a in Artist.objects.filter(musicbrainz_id__in=mbids)
|
||||
}
|
||||
for sa in similar:
|
||||
local = local_artists.get(sa.get("artist_mbid"))
|
||||
sa["local_url"] = local.get_absolute_url() if local else None
|
||||
context_data["similar_artists"] = similar
|
||||
|
||||
if artist.theaudiodb_genre:
|
||||
context_data["genre_count"] = (
|
||||
Artist.objects.filter(theaudiodb_genre=artist.theaudiodb_genre)
|
||||
.count()
|
||||
)
|
||||
if artist.theaudiodb_mood:
|
||||
context_data["mood_count"] = (
|
||||
Artist.objects.filter(theaudiodb_mood=artist.theaudiodb_mood)
|
||||
.count()
|
||||
)
|
||||
|
||||
return context_data
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user