diff --git a/vrobbler/apps/music/models.py b/vrobbler/apps/music/models.py index 38ee7df..aa10266 100644 --- a/vrobbler/apps/music/models.py +++ b/vrobbler/apps/music/models.py @@ -90,6 +90,24 @@ class Album(TimeStampedModel): def __str__(self): return self.name + def get_absolute_url(self): + return reverse("music:album_detail", kwargs={'slug': self.uuid}) + + def scrobbles(self): + from scrobbles.models import Scrobble + + return Scrobble.objects.filter( + track__in=self.track_set.all() + ).order_by('-timestamp') + + @property + def tracks(self): + return ( + self.track_set.all() + .annotate(scrobble_count=models.Count('scrobble')) + .order_by('-scrobble_count') + ) + @property def primary_artist(self): return self.artists.first() diff --git a/vrobbler/apps/music/urls.py b/vrobbler/apps/music/urls.py index 202749e..bf7e48f 100644 --- a/vrobbler/apps/music/urls.py +++ b/vrobbler/apps/music/urls.py @@ -6,6 +6,11 @@ app_name = 'music' urlpatterns = [ path('albums/', views.AlbumListView.as_view(), name='albums_list'), + path( + 'album//', + views.AlbumDetailView.as_view(), + name='album_detail', + ), path("tracks/", views.TrackListView.as_view(), name='tracks_list'), path( 'tracks//', diff --git a/vrobbler/apps/music/views.py b/vrobbler/apps/music/views.py index c3cbf3f..4b971c0 100644 --- a/vrobbler/apps/music/views.py +++ b/vrobbler/apps/music/views.py @@ -49,3 +49,15 @@ class ArtistDetailView(generic.DetailView): class AlbumListView(generic.ListView): model = Album + + +class AlbumDetailView(generic.DetailView): + model = Album + slug_field = 'uuid' + + def get_context_data(self, **kwargs): + context_data = super().get_context_data(**kwargs) + # context_data['charts'] = ChartRecord.objects.filter( + # track__album=self.object, rank__in=[1, 2, 3] + # ) + return context_data diff --git a/vrobbler/apps/scrobbles/theaudiodb.py b/vrobbler/apps/scrobbles/theaudiodb.py index 533673d..b315be9 100644 --- a/vrobbler/apps/scrobbles/theaudiodb.py +++ b/vrobbler/apps/scrobbles/theaudiodb.py @@ -23,11 +23,12 @@ def lookup_artist_from_tadb(name: str) -> dict: return {} results = json.loads(response.content) - artist = results['artists'][0] + if results['artists']: + artist = results['artists'][0] - artist_info['biography'] = artist['strBiographyEN'] - artist_info['genre'] = artist['strGenre'] - artist_info['mood'] = artist['strMood'] - artist_info['thumb_url'] = artist['strArtistThumb'] + artist_info['biography'] = artist['strBiographyEN'] + artist_info['genre'] = artist['strGenre'] + artist_info['mood'] = artist['strMood'] + artist_info['thumb_url'] = artist['strArtistThumb'] return artist_info diff --git a/vrobbler/templates/music/album_detail.html b/vrobbler/templates/music/album_detail.html new file mode 100644 index 0000000..63fd692 --- /dev/null +++ b/vrobbler/templates/music/album_detail.html @@ -0,0 +1,78 @@ +{% extends "base_list.html" %} +{% load mathfilters %} + +{% block title %}{{object.name}}{% endblock %} + +{% block lists %} + +
+ + {% if object.cover_image %} +

+ +

+ {% endif %} +
+
+

{{object.scrobbles.count}} scrobbles

+ {% if charts %} +

{% for chart in charts %}{{chart}}{% if forloop.last %}{% else %} | {% endif %}{% endfor %}

+ {% endif %} +
+

Top tracks

+
+ + + + + + + + + + + + {% for track in object.tracks %} + + + + + + + + {% endfor %} + +
RankTrackArtistCount
{{rank}}#1{{track.title}}{{track.artist}}{{track.scrobble_count}} +
+ +
+
+
+
+
+
+
+

Last scrobbles

+
+ + + + + + + + + + {% for scrobble in object.scrobbles %} + + + + + + {% endfor %} + +
DateTrackArtist
{{scrobble.timestamp}}{{scrobble.track.title}}{{scrobble.track.artist.name}}
+
+
+
+{% endblock %} diff --git a/vrobbler/templates/music/artist_detail.html b/vrobbler/templates/music/artist_detail.html index a442850..d80855a 100644 --- a/vrobbler/templates/music/artist_detail.html +++ b/vrobbler/templates/music/artist_detail.html @@ -6,11 +6,18 @@ {% block lists %}
- {% for album in artist.album_set.all %} - {% if album.cover_image %} -

+ + {% if object.thumbnail %} +

+ +

+ {% else %} + {% if object.album_set.first.cover_image %} +

+ +

+ {% endif %} {% endif %} - {% endfor %}

{{artist.scrobbles.count}} scrobbles

@@ -25,6 +32,7 @@ Rank Track + Album Count @@ -33,7 +41,8 @@ {% for track in object.tracks %} {{rank}}#1 - {{track.title}} + {{track.title}} + {{track.album}} {{track.scrobble_count}}
@@ -63,8 +72,8 @@ {% for scrobble in object.scrobbles %} {{scrobble.timestamp}} - {{scrobble.track.title}} - {{scrobble.track.album.name}} + {{scrobble.track.title}} + {{scrobble.track.album.name}} {% endfor %} diff --git a/vrobbler/templates/music/track_detail.html b/vrobbler/templates/music/track_detail.html index f301138..acec117 100644 --- a/vrobbler/templates/music/track_detail.html +++ b/vrobbler/templates/music/track_detail.html @@ -22,14 +22,16 @@ Date Track Album + Artist {% for scrobble in object.scrobble_set.all %} {{scrobble.timestamp}} - {{scrobble.track.title}} - {{scrobble.track.album.name}} + {{scrobble.track.title}} + {{scrobble.track.album}} + {{scrobble.track.artist}} {% endfor %}