From 76cc1f7b1c5b24e26c2f576e16bda1483e864d76 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 28 Mar 2023 15:24:04 -0400 Subject: [PATCH] Let's also thumbnail the now playing widget --- vrobbler/apps/books/models.py | 9 +++++---- vrobbler/apps/music/models.py | 10 +++++----- vrobbler/apps/podcasts/models.py | 8 ++++---- vrobbler/apps/scrobbles/mixins.py | 2 +- vrobbler/apps/sports/models.py | 10 +++++----- vrobbler/apps/videogames/models.py | 11 ++++++----- vrobbler/apps/videos/models.py | 8 ++++---- vrobbler/templates/base.html | 7 ++++++- 8 files changed, 36 insertions(+), 29 deletions(-) diff --git a/vrobbler/apps/books/models.py b/vrobbler/apps/books/models.py index 7c1f291..4284baf 100644 --- a/vrobbler/apps/books/models.py +++ b/vrobbler/apps/books/models.py @@ -1,5 +1,6 @@ import logging from datetime import timedelta +from typing import Optional from uuid import uuid4 import requests @@ -84,11 +85,11 @@ class Book(LongPlayScrobblableMixin): return f" by {self.author}" @property - def primary_image_url(self) -> str: - url = "" + def primary_image(self) -> Optional["ImageField"]: + img = None if self.cover: - url = self.cover.url - return url + img = self.cover + return img def get_start_url(self): return reverse("scrobbles:start", kwargs={"uuid": self.uuid}) diff --git a/vrobbler/apps/music/models.py b/vrobbler/apps/music/models.py index d907fd7..b460133 100644 --- a/vrobbler/apps/music/models.py +++ b/vrobbler/apps/music/models.py @@ -389,13 +389,13 @@ class Track(ScrobblableMixin): return self.mb_link @property - def primary_image_url(self) -> str: - url = "" + def primary_image(self) -> Optional["ImageField"]: + img = None if self.artist.thumbnail: - url = self.artist.thumbnail.url + img = self.artist.thumbnail if self.album and self.album.cover_image: - url = self.album.cover_image.url - return url + img = self.album.cover_image + return img @classmethod def find_or_create( diff --git a/vrobbler/apps/podcasts/models.py b/vrobbler/apps/podcasts/models.py index 3e28a88..d887eb6 100644 --- a/vrobbler/apps/podcasts/models.py +++ b/vrobbler/apps/podcasts/models.py @@ -96,11 +96,11 @@ class Episode(ScrobblableMixin): return "" @property - def primary_image_url(self) -> str: - url = "" + def primary_image(self) -> Optional["ImageField"]: + img = None if self.podcast.cover_image: - url = self.podcast.cover_image.url - return url + img = self.podcast.cover_image + return img @classmethod def find_or_create( diff --git a/vrobbler/apps/scrobbles/mixins.py b/vrobbler/apps/scrobbles/mixins.py index f68cfdc..2b98548 100644 --- a/vrobbler/apps/scrobbles/mixins.py +++ b/vrobbler/apps/scrobbles/mixins.py @@ -44,7 +44,7 @@ class ScrobblableMixin(TimeStampedModel): abstract = True @property - def primary_image_url(self) -> str: + def primary_image(self) -> Optional["ImageField"]: logger.warn(f"Not implemented yet") return "" diff --git a/vrobbler/apps/sports/models.py b/vrobbler/apps/sports/models.py index 2e987b6..12e7963 100644 --- a/vrobbler/apps/sports/models.py +++ b/vrobbler/apps/sports/models.py @@ -1,5 +1,5 @@ import logging -from typing import Dict +from typing import Dict, Optional from uuid import uuid4 from django.conf import settings @@ -142,11 +142,11 @@ class SportEvent(ScrobblableMixin): return self.sportsdb_link @property - def primary_image_url(self) -> str: - url = "" + def primary_image(self) -> Optional["ImageField"]: + img = None if self.round.season.league.logo: - url = self.round.season.league.logo.url - return url + img = self.round.season.league.logo + return img @classmethod def find_or_create(cls, data_dict: Dict) -> "Event": diff --git a/vrobbler/apps/videogames/models.py b/vrobbler/apps/videogames/models.py index a1951b1..f3f877d 100644 --- a/vrobbler/apps/videogames/models.py +++ b/vrobbler/apps/videogames/models.py @@ -1,4 +1,5 @@ import logging +from typing import Optional from uuid import uuid4 from django.conf import settings @@ -93,13 +94,13 @@ class VideoGame(LongPlayScrobblableMixin): return f" On {self.platforms.first()}" @property - def primary_image_url(self) -> str: - url = "" + def primary_image(self) -> Optional["ImageField"]: + img = None if self.cover: - url = self.cover.url + img = self.cover if self.hltb_cover: - url = self.hltb_cover.url - return url + img = self.hltb_cover + return img def get_absolute_url(self): return reverse( diff --git a/vrobbler/apps/videos/models.py b/vrobbler/apps/videos/models.py index 13f330b..eaa9208 100644 --- a/vrobbler/apps/videos/models.py +++ b/vrobbler/apps/videos/models.py @@ -155,11 +155,11 @@ class Video(ScrobblableMixin): return self.imdb_link @property - def primary_image_url(self) -> str: - url = "" + def primary_image(self) -> Optional["ImageField"]: + img = None if self.cover_image: - url = self.cover_image.url - return url + img = self.cover_image + return img def fix_metadata(self, force_update=False): imdb_dict = lookup_video_from_imdb(self.imdb_id) diff --git a/vrobbler/templates/base.html b/vrobbler/templates/base.html index 01ab88e..088f1a3 100644 --- a/vrobbler/templates/base.html +++ b/vrobbler/templates/base.html @@ -1,5 +1,6 @@ {% load static %} {% load humanize %} +{% load thumbnail %} @@ -245,7 +246,11 @@ Now playing {% for scrobble in now_playing_list %}
- {% if scrobble.media_obj.primary_image_url %}
{% endif %} + {% if scrobble.media_obj.primary_image %} + {% thumbnail scrobble.media_obj.primary_image 75x75 as im %} +
+ {% endthumbnail %} + {% endif %}

{{scrobble.media_obj.title}}

{% if scrobble.media_obj.subtitle %}

{{scrobble.media_obj.subtitle}}

{% endif %}

{{scrobble.timestamp|naturaltime}} from {{scrobble.source}}