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 import logging
from datetime import timedelta from datetime import timedelta
from typing import Optional
from uuid import uuid4 from uuid import uuid4
import requests import requests
@ -84,11 +85,11 @@ class Book(LongPlayScrobblableMixin):
return f" by {self.author}" return f" by {self.author}"
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
url = "" img = None
if self.cover: if self.cover:
url = self.cover.url img = self.cover
return url return img
def get_start_url(self): def get_start_url(self):
return reverse("scrobbles:start", kwargs={"uuid": self.uuid}) return reverse("scrobbles:start", kwargs={"uuid": self.uuid})

View File

@ -389,13 +389,13 @@ class Track(ScrobblableMixin):
return self.mb_link return self.mb_link
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
url = "" img = None
if self.artist.thumbnail: if self.artist.thumbnail:
url = self.artist.thumbnail.url img = self.artist.thumbnail
if self.album and self.album.cover_image: if self.album and self.album.cover_image:
url = self.album.cover_image.url img = self.album.cover_image
return url return img
@classmethod @classmethod
def find_or_create( def find_or_create(

View File

@ -96,11 +96,11 @@ class Episode(ScrobblableMixin):
return "" return ""
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
url = "" img = None
if self.podcast.cover_image: if self.podcast.cover_image:
url = self.podcast.cover_image.url img = self.podcast.cover_image
return url return img
@classmethod @classmethod
def find_or_create( def find_or_create(

View File

@ -44,7 +44,7 @@ class ScrobblableMixin(TimeStampedModel):
abstract = True abstract = True
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
logger.warn(f"Not implemented yet") logger.warn(f"Not implemented yet")
return "" return ""

View File

@ -1,5 +1,5 @@
import logging import logging
from typing import Dict from typing import Dict, Optional
from uuid import uuid4 from uuid import uuid4
from django.conf import settings from django.conf import settings
@ -142,11 +142,11 @@ class SportEvent(ScrobblableMixin):
return self.sportsdb_link return self.sportsdb_link
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
url = "" img = None
if self.round.season.league.logo: if self.round.season.league.logo:
url = self.round.season.league.logo.url img = self.round.season.league.logo
return url return img
@classmethod @classmethod
def find_or_create(cls, data_dict: Dict) -> "Event": def find_or_create(cls, data_dict: Dict) -> "Event":

View File

@ -1,4 +1,5 @@
import logging import logging
from typing import Optional
from uuid import uuid4 from uuid import uuid4
from django.conf import settings from django.conf import settings
@ -93,13 +94,13 @@ class VideoGame(LongPlayScrobblableMixin):
return f" On {self.platforms.first()}" return f" On {self.platforms.first()}"
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
url = "" img = None
if self.cover: if self.cover:
url = self.cover.url img = self.cover
if self.hltb_cover: if self.hltb_cover:
url = self.hltb_cover.url img = self.hltb_cover
return url return img
def get_absolute_url(self): def get_absolute_url(self):
return reverse( return reverse(

View File

@ -155,11 +155,11 @@ class Video(ScrobblableMixin):
return self.imdb_link return self.imdb_link
@property @property
def primary_image_url(self) -> str: def primary_image(self) -> Optional["ImageField"]:
url = "" img = None
if self.cover_image: if self.cover_image:
url = self.cover_image.url img = self.cover_image
return url return img
def fix_metadata(self, force_update=False): def fix_metadata(self, force_update=False):
imdb_dict = lookup_video_from_imdb(self.imdb_id) imdb_dict = lookup_video_from_imdb(self.imdb_id)

View File

@ -1,5 +1,6 @@
{% load static %} {% load static %}
{% load humanize %} {% load humanize %}
{% load thumbnail %}
<!doctype html> <!doctype html>
<html class="no-js" lang=""> <html class="no-js" lang="">
<head> <head>
@ -245,7 +246,11 @@
<b>Now playing</b> <b>Now playing</b>
{% for scrobble in now_playing_list %} {% for scrobble in now_playing_list %}
<div class="now-playing"> <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> <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 %} {% 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> <p><small>{{scrobble.timestamp|naturaltime}} from {{scrobble.source}}</small></p>