From d071319df42086090d33813aa77452bdbd660656 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Mon, 13 Mar 2023 14:43:08 -0400 Subject: [PATCH] Add video and series detail pages --- vrobbler/apps/videos/admin.py | 2 +- vrobbler/apps/videos/imdb.py | 1 + vrobbler/apps/videos/models.py | 43 +++++++---- vrobbler/apps/videos/views.py | 8 ++ .../templates/scrobbles/scrobble_list.html | 4 +- .../videogames/videogame_detail.html | 73 +++++++++++-------- vrobbler/templates/videos/series_detail.html | 56 ++++++++++++++ vrobbler/templates/videos/video_detail.html | 35 +++++++-- 8 files changed, 170 insertions(+), 52 deletions(-) create mode 100644 vrobbler/templates/videos/series_detail.html diff --git a/vrobbler/apps/videos/admin.py b/vrobbler/apps/videos/admin.py index ff9431f..43fe6ce 100644 --- a/vrobbler/apps/videos/admin.py +++ b/vrobbler/apps/videos/admin.py @@ -22,7 +22,7 @@ class VideoAdmin(admin.ModelAdmin): "tv_series", "season_number", "episode_number", - "imdb_id", + "imdb_rating", ) list_filter = ("year", "tv_series", "video_type") ordering = ("-created",) diff --git a/vrobbler/apps/videos/imdb.py b/vrobbler/apps/videos/imdb.py index 1eb0bc6..68437b7 100644 --- a/vrobbler/apps/videos/imdb.py +++ b/vrobbler/apps/videos/imdb.py @@ -37,6 +37,7 @@ def lookup_video_from_imdb(name_or_id: str, kind: str = "movie") -> dict: if not video_dict: logger.warn(f"No video found for key {name_or_id}") return video_dict + imdb_client.update(video_dict) cover_url = video_dict.get("cover url") if cover_url: diff --git a/vrobbler/apps/videos/models.py b/vrobbler/apps/videos/models.py index 1890cf0..b29c581 100644 --- a/vrobbler/apps/videos/models.py +++ b/vrobbler/apps/videos/models.py @@ -29,21 +29,30 @@ class Series(TimeStampedModel): genres = TaggableManager() - def __str__(self): - return self.name - - def imdb_link(self): - return f"https://www.imdb.com/title/{self.imdb_id}" - class Meta: verbose_name_plural = "series" + def __str__(self): + return self.name + + def get_absolute_url(self): + return reverse("videos:series_detail", kwargs={"slug": self.uuid}) + + def imdb_link(self): + return f"https://www.imdb.com/title/tt{self.imdb_id}" + + def scrobbles_for_user(self, user_id: int): + from scrobbles.models import Scrobble + + return Scrobble.objects.filter( + video__tv_series=self, user=user_id, played_to_completion=True + ).order_by("-timestamp") + def fix_metadata(self, force_update=False): imdb_dict = lookup_video_from_imdb(self.name, kind="tv series") - logger.info(imdb_dict) - self.imdb_id = imdb_dict.get("movieID") - self.imdb_rating = imdb_dict.get("rating") - self.plot = imdb_dict.get("plot outline") + self.imdb_id = imdb_dict.data.get("imdbID") + self.imdb_rating = imdb_dict.data.get("arithmetic mean") + self.plot = imdb_dict.data.get("plot outline") self.save(update_fields=["imdb_id", "imdb_rating", "plot"]) cover_url = imdb_dict.get("cover url") @@ -104,7 +113,7 @@ class Video(ScrobblableMixin): @property def imdb_link(self): - return f"https://www.imdb.com/title/{self.imdb_id}" + return f"https://www.imdb.com/title/tt{self.imdb_id}" @property def info_link(self): @@ -116,10 +125,14 @@ class Video(ScrobblableMixin): def fix_metadata(self, force_update=False): imdb_dict = lookup_video_from_imdb(self.imdb_id) - self.imdb_rating = imdb_dict.get("rating") - self.plot = imdb_dict.get("plot outline") - self.year = imdb_dict.get("year") - self.save(update_fields=["imdb_rating", "plot", "year"]) + if imdb_dict.get("runtimes") and len(imdb_dict.get("runtimes")) > 0: + self.run_time_seconds = int(imdb_dict.get("runtimes")[0]) * 60 + self.imdb_rating = imdb_dict.data.get("rating") + self.plot = imdb_dict.data.get("plot") + self.year = imdb_dict.data.get("year") + self.save( + update_fields=["imdb_rating", "plot", "year", "run_time_seconds"] + ) cover_url = imdb_dict.get("cover url") diff --git a/vrobbler/apps/videos/views.py b/vrobbler/apps/videos/views.py index 4440cae..53eee18 100644 --- a/vrobbler/apps/videos/views.py +++ b/vrobbler/apps/videos/views.py @@ -20,6 +20,14 @@ class SeriesDetailView(generic.DetailView): model = Series slug_field = "uuid" + def get_context_data(self, **kwargs): + context_data = super().get_context_data(**kwargs) + + context_data["scrobbles"] = self.object.scrobbles_for_user( + self.request.user.id + ) + return context_data + class VideoDetailView(generic.DetailView): model = Video diff --git a/vrobbler/templates/scrobbles/scrobble_list.html b/vrobbler/templates/scrobbles/scrobble_list.html index 03e7311..7166a18 100644 --- a/vrobbler/templates/scrobbles/scrobble_list.html +++ b/vrobbler/templates/scrobbles/scrobble_list.html @@ -504,8 +504,8 @@ {% for scrobble in video_scrobble_list %} {{scrobble.timestamp|naturaltime}} - {% if scrobble.video.tv_series%}S{{scrobble.video.season_number}}E{{scrobble.video.episode_number}} -{%endif %} {{scrobble.video.title}} - {% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}{% endif %} + {% if scrobble.video.tv_series%}S{{scrobble.video.season_number}}E{{scrobble.video.episode_number}} -{%endif %} {{scrobble.video.title}} + {% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}{% endif %} {% endfor %} diff --git a/vrobbler/templates/videogames/videogame_detail.html b/vrobbler/templates/videogames/videogame_detail.html index cd0c966..74a9d27 100644 --- a/vrobbler/templates/videogames/videogame_detail.html +++ b/vrobbler/templates/videogames/videogame_detail.html @@ -7,35 +7,47 @@ {% block head_extra %} -{% endblock %} +{% endblock %} {% block lists %}
- {% if object.hltb_cover%}
{% endif %}
{% if object.summary %}

{{object.summary|safe|linebreaks|truncatewords:160}}

-
+
{% endif %}

- - + +

{{object.scrobble_set.count}} scrobbles

-

{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}

+

{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete + %} and completed{% else %} spent playing{% endif %}

{% if object.scrobble_set.last.long_play_complete == True %} Play again @@ -49,26 +61,29 @@

Last scrobbles

- - - - - - - - - - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} - - + + + + + + + + + + {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + + - - - - {% endfor %} - + + + + {% endfor %} +
DateCompletedDurationPlatforms
{{scrobble.timestamp}}
DateCompletedDurationPlatforms
{{scrobble.timestamp}} {% if scrobble.long_play_complete == True %}Yes{% endif %}{% if scrobble.in_progress %}Now playing{% else %}{{scrobble.playback_position_seconds|natural_duration}}{% endif %}{% for platform in scrobble.video_game.platforms.all %}{{platform}}{% if not forloop.last %}, {% endif %}{% endfor %}
{% if scrobble.in_progress %}Now playing{% else + %}{{scrobble.playback_position_seconds|natural_duration}}{% endif %}{% for platform in scrobble.video_game.platforms.all %}{{platform}}{% if not forloop.last %}, {% endif + %}{% endfor %}
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/vrobbler/templates/videos/series_detail.html b/vrobbler/templates/videos/series_detail.html new file mode 100644 index 0000000..941432b --- /dev/null +++ b/vrobbler/templates/videos/series_detail.html @@ -0,0 +1,56 @@ +{% extends "base_list.html" %} +{% load static %} + +{% block title %}{{object.title}}{% if object.tv_series %} - {{object.tv_series}}{% endif %}{% endblock %} + +{% block head_extra %} + +{% endblock %} + +{% block lists %} + +
+ {% if object.cover_image %} +
+ {% endif %} +
+ {% if object.plot%} +

{{object.plot|safe|linebreaks|truncatewords:160}}

+
+ {% endif %} +

+ +

+
+
+
+
+

Last scrobbles

+
+ + + + + + + + + + + {% for scrobble in scrobbles %} + + + + + + + {% endfor %} + +
DateTitleSeasonEpisode
{{scrobble.timestamp}}{{scrobble.media_obj.title}}{{scrobble.media_obj.season_number}}{{scrobble.media_obj.episode_number}}
+
+
+
+{% endblock %} diff --git a/vrobbler/templates/videos/video_detail.html b/vrobbler/templates/videos/video_detail.html index 080bf1c..edebeac 100644 --- a/vrobbler/templates/videos/video_detail.html +++ b/vrobbler/templates/videos/video_detail.html @@ -1,8 +1,35 @@ -{% extends "base_detail.html" %} +{% extends "base_list.html" %} +{% load static %} {% block title %}{{object.title}}{% if object.tv_series %} - {{object.tv_series}}{% endif %}{% endblock %} -{% block details %} +{% block head_extra %} + +{% endblock %} + +{% block lists %} + +
+ {% if object.cover_image %} +
+ {% endif %} +
+ {% if object.overview %} +

{{object.overview}}

+ {% endif %} + {% if object.plot%} +

{{object.plot|safe|linebreaks|truncatewords:160}}

+
+ {% endif %} +

+ + +

+
+

Last scrobbles

@@ -11,7 +38,6 @@ Date - Title {% if object.tv_series %} Series Season @@ -23,9 +49,8 @@ {% for scrobble in object.scrobble_set.all %} {{scrobble.timestamp}} - {{scrobble.video.title}} {% if object.tv_series %} - {{scrobble.video.tv_series}} + {{scrobble.video.tv_series}} {{scrobble.video.season_number}} {{scrobble.video.episode_number}} {% endif %}