Let's also thumbnail the now playing widget

This commit is contained in:
2023-03-28 15:24:04 -04:00
parent c39430e987
commit 76cc1f7b1c
8 changed files with 36 additions and 29 deletions

View File

@ -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})

View File

@ -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(

View File

@ -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(

View File

@ -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 ""

View File

@ -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":

View File

@ -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(

View File

@ -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)

View File

@ -1,5 +1,6 @@
{% load static %}
{% load humanize %}
{% load thumbnail %}
<!doctype html>
<html class="no-js" lang="">
<head>
@ -245,7 +246,11 @@
<b>Now playing</b>
{% for scrobble in now_playing_list %}
<div class="now-playing">
{% if scrobble.media_obj.primary_image_url %}<div style="float:left;padding-right:10px;padding-bottom:10px;"><img src="{{scrobble.media_obj.primary_image_url}}" /></div>{% endif %}
{% if scrobble.media_obj.primary_image %}
{% thumbnail scrobble.media_obj.primary_image 75x75 as im %}
<div style="float:left;padding-right:10px;padding-bottom:10px;"><img src="{{im.url}}" width={{im.width}} height={{im.height}} /></div>
{% endthumbnail %}
{% endif %}
<p><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></p>
{% if scrobble.media_obj.subtitle %}<p><em><a href="{{scrobble.media_obj.subtitle.get_absolute_url}}">{{scrobble.media_obj.subtitle}}</a></em></p>{% endif %}
<p><small>{{scrobble.timestamp|naturaltime}} from {{scrobble.source}}</small></p>