Add even more imagekit gloriousness

This commit is contained in:
2023-11-30 23:37:42 +01:00
parent 61c10db0dd
commit 63ddb51e89
7 changed files with 153 additions and 21 deletions

View File

@ -10,6 +10,8 @@ from django.core.files.base import ContentFile
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django_extensions.db.models import TimeStampedModel from django_extensions.db.models import TimeStampedModel
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFit
from scrobbles.mixins import ScrobblableMixin from scrobbles.mixins import ScrobblableMixin
from vrobbler.apps.boardgames.bgg import lookup_boardgame_id_from_bgg from vrobbler.apps.boardgames.bgg import lookup_boardgame_id_from_bgg
@ -54,7 +56,31 @@ class BoardGame(ScrobblableMixin):
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL) uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
description = models.TextField(**BNULL) description = models.TextField(**BNULL)
cover = models.ImageField(upload_to="boardgames/covers/", **BNULL) cover = models.ImageField(upload_to="boardgames/covers/", **BNULL)
cover_small = ImageSpecField(
source="cover",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
cover_medium = ImageSpecField(
source="cover",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
layout_image = models.ImageField(upload_to="boardgames/layouts/", **BNULL) layout_image = models.ImageField(upload_to="boardgames/layouts/", **BNULL)
layout_image_small = ImageSpecField(
source="layout_image",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
layout_image_medium = ImageSpecField(
source="layout_image",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
rating = models.FloatField(**BNULL) rating = models.FloatField(**BNULL)
max_players = models.PositiveSmallIntegerField(**BNULL) max_players = models.PositiveSmallIntegerField(**BNULL)
min_players = models.PositiveSmallIntegerField(**BNULL) min_players = models.PositiveSmallIntegerField(**BNULL)

View File

@ -13,6 +13,8 @@ from django.core.files.base import ContentFile
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django_extensions.db.models import TimeStampedModel from django_extensions.db.models import TimeStampedModel
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFit
from scrobbles.mixins import ( from scrobbles.mixins import (
LongPlayScrobblableMixin, LongPlayScrobblableMixin,
ObjectWithGenres, ObjectWithGenres,
@ -37,6 +39,18 @@ class Author(TimeStampedModel):
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL) uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
openlibrary_id = models.CharField(max_length=255, **BNULL) openlibrary_id = models.CharField(max_length=255, **BNULL)
headshot = models.ImageField(upload_to="books/authors/", **BNULL) headshot = models.ImageField(upload_to="books/authors/", **BNULL)
headshot_small = ImageSpecField(
source="headshot",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
headshot_medium = ImageSpecField(
source="headshot",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
bio = models.TextField(**BNULL) bio = models.TextField(**BNULL)
wikipedia_url = models.CharField(max_length=255, **BNULL) wikipedia_url = models.CharField(max_length=255, **BNULL)
isni = models.CharField(max_length=255, **BNULL) isni = models.CharField(max_length=255, **BNULL)
@ -88,6 +102,18 @@ class Book(LongPlayScrobblableMixin):
openlibrary_id = models.CharField(max_length=255, **BNULL) openlibrary_id = models.CharField(max_length=255, **BNULL)
locg_slug = models.CharField(max_length=255, **BNULL) locg_slug = models.CharField(max_length=255, **BNULL)
cover = models.ImageField(upload_to="books/covers/", **BNULL) cover = models.ImageField(upload_to="books/covers/", **BNULL)
cover_small = ImageSpecField(
source="cover",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
cover_medium = ImageSpecField(
source="cover",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
summary = models.TextField(**BNULL) summary = models.TextField(**BNULL)
genre = TaggableManager(through=ObjectWithGenres) genre = TaggableManager(through=ObjectWithGenres)
@ -103,7 +129,7 @@ class Book(LongPlayScrobblableMixin):
def primary_image_url(self) -> str: def primary_image_url(self) -> str:
url = "" url = ""
if self.cover: if self.cover:
url = self.cover.url url = self.cover_medium.url
return url return url
def get_start_url(self): def get_start_url(self):

View File

@ -13,7 +13,7 @@ from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django_extensions.db.models import TimeStampedModel from django_extensions.db.models import TimeStampedModel
from imagekit.models import ImageSpecField from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill from imagekit.processors import ResizeToFit
from music.allmusic import get_allmusic_slug, scrape_data_from_allmusic from music.allmusic import get_allmusic_slug, scrape_data_from_allmusic
from music.bandcamp import get_bandcamp_slug from music.bandcamp import get_bandcamp_slug
from music.theaudiodb import lookup_album_from_tadb, lookup_artist_from_tadb from music.theaudiodb import lookup_album_from_tadb, lookup_artist_from_tadb
@ -36,13 +36,13 @@ class Artist(TimeStampedModel):
thumbnail = models.ImageField(upload_to="artist/", **BNULL) thumbnail = models.ImageField(upload_to="artist/", **BNULL)
thumbnail_small = ImageSpecField( thumbnail_small = ImageSpecField(
source="thumbnail", source="thumbnail",
processors=[ResizeToFill(100)], processors=[ResizeToFit(100, 100)],
format="JPEG", format="JPEG",
options={"quality": 60}, options={"quality": 60},
) )
thumbnail_medium = ImageSpecField( thumbnail_medium = ImageSpecField(
source="thumbnail", source="thumbnail",
processors=[ResizeToFill(300)], processors=[ResizeToFit(300, 300)],
format="JPEG", format="JPEG",
options={"quality": 75}, options={"quality": 75},
) )
@ -168,13 +168,13 @@ class Album(TimeStampedModel):
cover_image = models.ImageField(upload_to="albums/", **BNULL) cover_image = models.ImageField(upload_to="albums/", **BNULL)
cover_image_small = ImageSpecField( cover_image_small = ImageSpecField(
source="cover_image", source="cover_image",
processors=[ResizeToFill(100)], processors=[ResizeToFit(100)],
format="JPEG", format="JPEG",
options={"quality": 60}, options={"quality": 60},
) )
cover_image_medium = ImageSpecField( cover_image_medium = ImageSpecField(
source="cover_image", source="cover_image",
processors=[ResizeToFill(300)], processors=[ResizeToFit(300)],
format="JPEG", format="JPEG",
options={"quality": 75}, options={"quality": 75},
) )
@ -213,7 +213,7 @@ class Album(TimeStampedModel):
@property @property
def primary_image_url(self) -> str: def primary_image_url(self) -> str:
if self.cover_image.url: if self.cover_image.url:
return self.cover_image.url return self.cover_image_medium.url
return "" return ""
@property @property
@ -440,9 +440,9 @@ class Track(ScrobblableMixin):
def primary_image_url(self) -> str: def primary_image_url(self) -> str:
url = "" url = ""
if self.artist.thumbnail: if self.artist.thumbnail:
url = self.artist.thumbnail.url url = self.artist.thumbnail_medium.url
if self.album and self.album.cover_image: if self.album and self.album.cover_image:
url = self.album.cover_image.url url = self.album.cover_image_medium.url
return url return url
@classmethod @classmethod

View File

@ -6,6 +6,8 @@ from django.contrib.auth import get_user_model
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django_extensions.db.models import TimeStampedModel from django_extensions.db.models import TimeStampedModel
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFit
from scrobbles.mixins import LongPlayScrobblableMixin from scrobbles.mixins import LongPlayScrobblableMixin
from scrobbles.utils import get_scrobbles_for_media from scrobbles.utils import get_scrobbles_for_media
from videogames.igdb import lookup_game_id_from_gdb from videogames.igdb import lookup_game_id_from_gdb
@ -34,6 +36,18 @@ class VideoGameCollection(TimeStampedModel):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL) uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
cover = models.ImageField(upload_to="games/series-covers/", **BNULL) cover = models.ImageField(upload_to="games/series-covers/", **BNULL)
cover_small = ImageSpecField(
source="cover",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
cover_medium = ImageSpecField(
source="cover",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
igdb_id = models.IntegerField(**BNULL) igdb_id = models.IntegerField(**BNULL)
def __str__(self): def __str__(self):
@ -72,9 +86,45 @@ class VideoGame(LongPlayScrobblableMixin):
alternative_name = models.CharField(max_length=255, **BNULL) alternative_name = models.CharField(max_length=255, **BNULL)
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL) uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
cover = models.ImageField(upload_to="games/covers/", **BNULL) cover = models.ImageField(upload_to="games/covers/", **BNULL)
cover_small = ImageSpecField(
source="cover",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
cover_medium = ImageSpecField(
source="cover",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
screenshot = models.ImageField(upload_to="games/screenshots/", **BNULL) screenshot = models.ImageField(upload_to="games/screenshots/", **BNULL)
screenshot_small = ImageSpecField(
source="screenshot",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
screenshot_medium = ImageSpecField(
source="screenshot",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
summary = models.TextField(**BNULL) summary = models.TextField(**BNULL)
hltb_cover = models.ImageField(upload_to="games/hltb_covers/", **BNULL) hltb_cover = models.ImageField(upload_to="games/hltb_covers/", **BNULL)
hltb_cover_small = ImageSpecField(
source="htlb_cover",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
hltb_cover_medium = ImageSpecField(
source="hltb_cover",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
rating = models.FloatField(**BNULL) rating = models.FloatField(**BNULL)
rating_count = models.IntegerField(**BNULL) rating_count = models.IntegerField(**BNULL)
release_date = models.DateTimeField(**BNULL) release_date = models.DateTimeField(**BNULL)
@ -97,9 +147,9 @@ class VideoGame(LongPlayScrobblableMixin):
def primary_image_url(self) -> str: def primary_image_url(self) -> str:
url = "" url = ""
if self.cover: if self.cover:
url = self.cover.url url = self.cover_medium.url
if self.hltb_cover: if self.hltb_cover:
url = self.hltb_cover.url url = self.hltb_cover_medium.url
return url return url
def get_absolute_url(self): def get_absolute_url(self):

View File

@ -9,9 +9,10 @@ from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django_extensions.db.models import TimeStampedModel from django_extensions.db.models import TimeStampedModel
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFit
from scrobbles.mixins import ObjectWithGenres, ScrobblableMixin from scrobbles.mixins import ObjectWithGenres, ScrobblableMixin
from taggit.managers import TaggableManager from taggit.managers import TaggableManager
from videos.imdb import lookup_video_from_imdb from videos.imdb import lookup_video_from_imdb
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -25,6 +26,18 @@ class Series(TimeStampedModel):
imdb_id = models.CharField(max_length=20, **BNULL) imdb_id = models.CharField(max_length=20, **BNULL)
imdb_rating = models.FloatField(**BNULL) imdb_rating = models.FloatField(**BNULL)
cover_image = models.ImageField(upload_to="videos/series/", **BNULL) cover_image = models.ImageField(upload_to="videos/series/", **BNULL)
cover_small = ImageSpecField(
source="cover_image",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
cover_medium = ImageSpecField(
source="cover_image",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
preferred_source = models.CharField(max_length=100, **BNULL) preferred_source = models.CharField(max_length=100, **BNULL)
genre = TaggableManager(through=ObjectWithGenres) genre = TaggableManager(through=ObjectWithGenres)
@ -41,6 +54,13 @@ class Series(TimeStampedModel):
def imdb_link(self): def imdb_link(self):
return f"https://www.imdb.com/title/tt{self.imdb_id}" return f"https://www.imdb.com/title/tt{self.imdb_id}"
@property
def primary_image_url(self) -> str:
url = ""
if self.cover_image:
url = self.cover_image_medium.url
return url
def scrobbles_for_user(self, user_id: int, include_playing=False): def scrobbles_for_user(self, user_id: int, include_playing=False):
from scrobbles.models import Scrobble from scrobbles.models import Scrobble
@ -120,6 +140,18 @@ class Video(ScrobblableMixin):
imdb_id = models.CharField(max_length=20, **BNULL) imdb_id = models.CharField(max_length=20, **BNULL)
imdb_rating = models.FloatField(**BNULL) imdb_rating = models.FloatField(**BNULL)
cover_image = models.ImageField(upload_to="videos/video/", **BNULL) cover_image = models.ImageField(upload_to="videos/video/", **BNULL)
cover_small = ImageSpecField(
source="cover_image",
processors=[ResizeToFit(100, 100)],
format="JPEG",
options={"quality": 60},
)
cover_medium = ImageSpecField(
source="cover_image",
processors=[ResizeToFit(300, 300)],
format="JPEG",
options={"quality": 75},
)
tvrage_id = models.CharField(max_length=20, **BNULL) tvrage_id = models.CharField(max_length=20, **BNULL)
tvdb_id = models.CharField(max_length=20, **BNULL) tvdb_id = models.CharField(max_length=20, **BNULL)
plot = models.TextField(**BNULL) plot = models.TextField(**BNULL)
@ -158,7 +190,7 @@ class Video(ScrobblableMixin):
def primary_image_url(self) -> str: def primary_image_url(self) -> str:
url = "" url = ""
if self.cover_image: if self.cover_image:
url = self.cover_image.url url = self.cover_image_medium.url
return url return url
def fix_metadata(self, force_update=False): def fix_metadata(self, force_update=False):

View File

@ -1,11 +1,7 @@
<div class="col-sm"> <div class="col-sm">
<dl> <dl>
<dt><a href="{{media.get_absolute_url}}">{{media.title}}</a></dt> <dt><a href="{{media.get_absolute_url}}">{{media.title}}</a></dt>
{% if media.hltb_cover %} <dd><a href="{{media.get_absolute_url}}"><img src="{{media.primary_image_url}}" style="width: 200px; height: 200px; object-fit:cover; " /></a></dd>
<dd><a href="{{media.get_absolute_url}}"><img src="{{media.hltb_cover.url}}" width=300 height=300 /></a></dd>
{% elif media.cover %}
<dd><a href="{{media.get_absolute_url}}"><img src="{{media.cover.url}}" style="width: 200px; height: 200px; object-fit:cover; " /></a></dd>
{% endif %}
<dd> <dd>
{% if media.is_long_play_in_progress %}Playing{% else %}<a type="button" class="btn btn-sm btn-primary" href="{{media.get_start_url}}">Resume</a>{% endif %} {% if media.is_long_play_in_progress %}Playing{% else %}<a type="button" class="btn btn-sm btn-primary" href="{{media.get_start_url}}">Resume</a>{% endif %}
<a type="button" class="right btn btn-sm " href="{{media.get_longplay_finish_url}}">Finish</a> <a type="button" class="right btn btn-sm " href="{{media.get_longplay_finish_url}}">Finish</a>

View File

@ -162,6 +162,7 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Time</th> <th scope="col">Time</th>
<th scope="col">Cover</th>
<th scope="col">Title</th> <th scope="col">Title</th>
<th scope="col">Series</th> <th scope="col">Series</th>
</tr> </tr>
@ -170,6 +171,7 @@
{% for scrobble in video_scrobble_list %} {% for scrobble in video_scrobble_list %}
<tr> <tr>
<td>{{scrobble.timestamp|naturaltime}}</td> <td>{{scrobble.timestamp|naturaltime}}</td>
<td><img src="{{scrobble.media_obj.cover_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
<td><a href="{{scrobble.video.get_absolute_url }}">{% if scrobble.video.tv_series%}S{{scrobble.video.season_number}}E{{scrobble.video.episode_number}} -{%endif %} {{scrobble.video.title}}</a></td> <td><a href="{{scrobble.video.get_absolute_url }}">{% if scrobble.video.tv_series%}S{{scrobble.video.season_number}}E{{scrobble.video.episode_number}} -{%endif %} {{scrobble.video.title}}</a></td>
<td><a href="{{scrobble.video.tv_series.get_absolute_url }}">{% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}</a>{% endif %} <td><a href="{{scrobble.video.tv_series.get_absolute_url }}">{% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}</a>{% endif %}
</td> </td>
@ -250,9 +252,9 @@
<tr> <tr>
<td>{{scrobble.timestamp|naturaltime}}</td> <td>{{scrobble.timestamp|naturaltime}}</td>
{% if scrobble.videogame_screenshot %} {% if scrobble.videogame_screenshot %}
<td><img src="{{scrobble.videogame_screenshot.url}}" width=25 height=25 style="border:1px solid black;" /></td> <td><img src="{{scrobble.videogame_screenshot_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
{% else %} {% else %}
<td><img src="{{scrobble.media_obj.primary_image_url}}" width=25 height=25 style="border:1px solid black;" /></td> <td><img src="{{scrobble.media_obj.cover_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
{% endif %} {% endif %}
<td><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></td> <td><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></td>
<td>{{scrobble.playback_position_seconds|natural_duration}}</td> <td>{{scrobble.playback_position_seconds|natural_duration}}</td>
@ -282,7 +284,7 @@
{% for scrobble in boardgame_scrobble_list %} {% for scrobble in boardgame_scrobble_list %}
<tr> <tr>
<td>{{scrobble.timestamp|naturaltime}}</td> <td>{{scrobble.timestamp|naturaltime}}</td>
<td><img src="{{scrobble.media_obj.primary_image_url}}" width=25 height=25 style="border:1px solid black;" /></td> <td><img src="{{scrobble.media_obj.cover_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
<td><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></td> <td><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></td>
<td>{{scrobble.playback_position_seconds|natural_duration}}</td> <td>{{scrobble.playback_position_seconds|natural_duration}}</td>
</tr> </tr>