diff --git a/poetry.lock b/poetry.lock index 7f3c6fa..09e21b2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -970,6 +970,20 @@ python3-openid = ">=3.0.8" requests = "*" requests-oauthlib = ">=0.3.0" +[[package]] +name = "django-appconf" +version = "1.0.6" +description = "A helper class for handling configuration defaults of packaged apps gracefully." +optional = false +python-versions = ">=3.7" +files = [ + {file = "django-appconf-1.0.6.tar.gz", hash = "sha256:cfe87ea827c4ee04b9a70fab90b86d704cb02f2981f89da8423cb0fabf88efbf"}, + {file = "django_appconf-1.0.6-py3-none-any.whl", hash = "sha256:c3ae442fba1ff7ec830412c5184b17169a7a1e71cf0864a4c3f93cf4c98a1993"}, +] + +[package.dependencies] +django = "*" + [[package]] name = "django-celery-results" version = "2.5.0" @@ -1027,6 +1041,26 @@ files = [ [package.dependencies] Django = ">=2.2" +[[package]] +name = "django-imagekit" +version = "5.0.0" +description = "Automated image processing for Django models." +optional = false +python-versions = "*" +files = [ + {file = "django-imagekit-5.0.0.tar.gz", hash = "sha256:aae9f74a8e9b6ceb5d15f7d8e266302901e76d9f532c78bd5135cb0fa206a6b0"}, + {file = "django_imagekit-5.0.0-py3-none-any.whl", hash = "sha256:a8e77ed6549751026a51f961bb2cd5fda739be691496da8eecbe68ffb966c261"}, +] + +[package.dependencies] +django-appconf = "*" +pilkit = "*" + +[package.extras] +async = ["django-celery (>=3.0)"] +async-dramatiq = ["django-dramatiq (>=0.4.0)"] +async-rq = ["django-rq (>=0.6.0)"] + [[package]] name = "django-markdownify" version = "0.9.3" @@ -2293,6 +2327,20 @@ files = [ {file = "pickleshare-0.7.5.tar.gz", hash = "sha256:87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca"}, ] +[[package]] +name = "pilkit" +version = "3.0" +description = "A collection of utilities and processors for the Python Imaging Library." +optional = false +python-versions = "*" +files = [ + {file = "pilkit-3.0-py3-none-any.whl", hash = "sha256:fe1707b0411a1d0cbf9ad3986779fa5a346cec4582a188740924aa39f504d117"}, + {file = "pilkit-3.0.tar.gz", hash = "sha256:f6719e8cc0482e5447f5cb94f18b949d8e604ea9673a9b019c74d41b779e4eab"}, +] + +[package.dependencies] +Pillow = ">=7.0" + [[package]] name = "pillow" version = "9.4.0" @@ -3954,4 +4002,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0" -content-hash = "47f7ab7850d11723274d6fafdf072a90618898a66d9dc6c845d1424df1944d77" +content-hash = "4ef8573c3329873d231c5b162e685f5e53d206f5f0bac592dde455fc211df349" diff --git a/pyproject.toml b/pyproject.toml index 80e556c..cb498d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ stream-sqlite = "^0.0.41" ipython = "^8.14.0" pendulum = "^2.1.2" trafilatura = "^1.6.3" +django-imagekit = "^5.0.0" [tool.poetry.dev-dependencies] Werkzeug = "2.0.3" diff --git a/vrobbler/apps/music/models.py b/vrobbler/apps/music/models.py index ae7e49f..e9dba31 100644 --- a/vrobbler/apps/music/models.py +++ b/vrobbler/apps/music/models.py @@ -12,6 +12,8 @@ from django.db import models from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django_extensions.db.models import TimeStampedModel +from imagekit.models import ImageSpecField +from imagekit.processors import ResizeToFill from music.allmusic import get_allmusic_slug, scrape_data_from_allmusic from music.bandcamp import get_bandcamp_slug from music.theaudiodb import lookup_album_from_tadb, lookup_artist_from_tadb @@ -32,6 +34,18 @@ class Artist(TimeStampedModel): allmusic_id = models.CharField(max_length=100, **BNULL) bandcamp_id = models.CharField(max_length=100, **BNULL) thumbnail = models.ImageField(upload_to="artist/", **BNULL) + thumbnail_small = ImageSpecField( + source="thumbnail", + processors=[ResizeToFill(100)], + format="JPEG", + options={"quality": 60}, + ) + thumbnail_medium = ImageSpecField( + source="thumbnail", + processors=[ResizeToFill(300)], + format="JPEG", + options={"quality": 75}, + ) class Meta: unique_together = [["name", "musicbrainz_id"]] @@ -152,6 +166,18 @@ class Album(TimeStampedModel): musicbrainz_releasegroup_id = models.CharField(max_length=255, **BNULL) musicbrainz_albumartist_id = models.CharField(max_length=255, **BNULL) cover_image = models.ImageField(upload_to="albums/", **BNULL) + cover_image_small = ImageSpecField( + source="cover_image", + processors=[ResizeToFill(100)], + format="JPEG", + options={"quality": 60}, + ) + cover_image_medium = ImageSpecField( + source="cover_image", + processors=[ResizeToFill(300)], + format="JPEG", + options={"quality": 75}, + ) theaudiodb_id = models.CharField(max_length=255, unique=True, **BNULL) theaudiodb_description = models.TextField(**BNULL) theaudiodb_year_released = models.IntegerField(**BNULL) diff --git a/vrobbler/settings-testing.py b/vrobbler/settings-testing.py index 0699426..345c830 100644 --- a/vrobbler/settings-testing.py +++ b/vrobbler/settings-testing.py @@ -93,6 +93,7 @@ INSTALLED_APPS = [ "django.contrib.humanize", "django_filters", "django_extensions", + "imagekit", "storages", "taggit", "rest_framework.authtoken", diff --git a/vrobbler/settings.py b/vrobbler/settings.py index 2f067bf..4f19387 100644 --- a/vrobbler/settings.py +++ b/vrobbler/settings.py @@ -101,6 +101,7 @@ INSTALLED_APPS = [ "django.contrib.humanize", "django_filters", "django_extensions", + "imagekit", "storages", "taggit", "rest_framework.authtoken", diff --git a/vrobbler/templates/scrobbles/scrobble_list.html b/vrobbler/templates/scrobbles/scrobble_list.html index ad2309d..8e04a78 100644 --- a/vrobbler/templates/scrobbles/scrobble_list.html +++ b/vrobbler/templates/scrobbles/scrobble_list.html @@ -141,7 +141,7 @@