diff --git a/PROJECT.org b/PROJECT.org index e03ccf4..d0ef1cf 100644 --- a/PROJECT.org +++ b/PROJECT.org @@ -88,7 +88,7 @@ fetching and simple saving. *** Metadata sources **** Scraper -* Backlog [0/20] :vrobbler:project:personal: +* Backlog [1/21] :vrobbler:project:personal: ** TODO [#C] Create small utility to clean up tracks scrobbled with wonky playback times :bug:music:scrobbles: :PROPERTIES: :ID: 702462cf-d54b-48c6-8a7c-78b8de751deb @@ -594,7 +594,18 @@ named constants for maintainability. - ~vrobbler/apps/webpages/models.py~ (line 290) -- ="url"= - ~vrobbler/apps/scrobbles/importers/tsv.py~ (line 55) -- ="S"= completion status -** TODO [#C] Show time per scrobble in long play lists and total time playing :templates:longplay:scrobbles: +** DONE [#C] Show time per scrobble in long play lists and total time playing :templates:longplay:scrobbles: +:PROPERTIES: +:ID: b3d16230-8ec5-46db-b166-59e98d0ee06c +:END: + +*** Description + +Long play time should be show in the table of scrobbles on a media detail page. +The total time spent in a long play that's either no completed yet or completed +should be displayed as well. If completed, the date finished should be shown as +well. + * Version 52.0 [5/5] ** DONE [#B] Allow marking media as long play complete from detail page :templates:scrobbles:longplay: :PROPERTIES: diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index d61d2ac..92fb3bc 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -206,6 +206,19 @@ class ScrobbleableDetailView(ChartContextMixin, DetailView): context_data["scrobbles"] = page_obj.object_list context_data["is_paginated"] = paginator.num_pages > 1 + media = self.object + if hasattr(media, "is_long_play_media") and media.is_long_play_media(): + qs = media.scrobble_set.filter(user=self.request.user) + completed = qs.filter(long_play_complete=True).order_by("-timestamp").first() + if completed and completed.long_play_seconds: + context_data["long_play_total_seconds"] = completed.long_play_seconds + context_data["long_play_finished_date"] = completed.timestamp + else: + latest_finished = qs.filter(played_to_completion=True).order_by("-timestamp").first() + if latest_finished and latest_finished.long_play_seconds: + context_data["long_play_total_seconds"] = latest_finished.long_play_seconds + context_data["long_play_finished_date"] = None + return context_data @@ -1297,6 +1310,24 @@ class ScrobbleDetailView(DetailView): else: context["has_mopidy_uri"] = False + if self.object.is_long_play and fk_field: + all_scrobbles = Scrobble.objects.filter( + user=user, **{fk_field: media_obj} + ) + completed = all_scrobbles.filter( + long_play_complete=True + ).order_by("-timestamp").first() + if completed and completed.long_play_seconds: + context["long_play_total_seconds"] = completed.long_play_seconds + context["long_play_finished_date"] = completed.timestamp + else: + latest_finished = all_scrobbles.filter( + played_to_completion=True + ).order_by("-timestamp").first() + if latest_finished and latest_finished.long_play_seconds: + context["long_play_total_seconds"] = latest_finished.long_play_seconds + context["long_play_finished_date"] = None + return context diff --git a/vrobbler/templates/_longplay_scrobblable_list.html b/vrobbler/templates/_longplay_scrobblable_list.html index e6d48fc..18428bb 100644 --- a/vrobbler/templates/_longplay_scrobblable_list.html +++ b/vrobbler/templates/_longplay_scrobblable_list.html @@ -6,6 +6,7 @@
{{scrobbles.count}} scrobbles
++ {{scrobbles.count}} scrobbles + {% if long_play_total_seconds %} | Total time: {{ long_play_total_seconds|natural_duration }}{% endif %} + {% if long_play_finished_date %} | Finished: {{ long_play_finished_date|date:"M d, Y" }}{% endif %} +
diff --git a/vrobbler/templates/bricksets/brickset_detail.html b/vrobbler/templates/bricksets/brickset_detail.html index 731d83c..814fe67 100644 --- a/vrobbler/templates/bricksets/brickset_detail.html +++ b/vrobbler/templates/bricksets/brickset_detail.html @@ -26,7 +26,11 @@{{scrobbles.count}} scrobbles
++ {{scrobbles.count}} scrobbles + {% if long_play_total_seconds %} | Total time: {{ long_play_total_seconds|natural_duration }}{% endif %} + {% if long_play_finished_date %} | Finished: {{ long_play_finished_date|date:"M d, Y" }}{% endif %} +
{{ related_scrobbles.paginator.count }} scrobble{{ related_scrobbles.paginator.count|pluralize }}
++ {{ related_scrobbles.paginator.count }} scrobble{{ related_scrobbles.paginator.count|pluralize }} + {% if object.is_long_play and long_play_total_seconds %} + | Total time: {{ long_play_total_seconds|natural_duration }} + {% if long_play_finished_date %} | Finished: {{ long_play_finished_date|date:"M d, Y" }}{% endif %} + {% endif %} +
| - {% if scrobble.playback_position_seconds %}{{ scrobble.playback_position_seconds|natural_duration }}{% endif %} + {% if scrobble.is_long_play and scrobble.long_play_seconds %} + {{ scrobble.playback_position_seconds|natural_duration }} ({{ scrobble.long_play_seconds|natural_duration }} total) + {% elif scrobble.playback_position_seconds %} + {{ scrobble.playback_position_seconds|natural_duration }} + {% endif %} |