Add image format conversion after downloading box art and campaign images
This commit is contained in:
parent
c092d3089f
commit
51095796e9
2 changed files with 21 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ from urllib.parse import urlparse
|
||||||
import httpx
|
import httpx
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
from django.core.management import call_command
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
@ -38,7 +39,7 @@ class Command(BaseCommand):
|
||||||
help="Re-download even if a local box art file already exists.",
|
help="Re-download even if a local box art file already exists.",
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle(self, *_args: object, **options: object) -> None: # noqa: PLR0914
|
def handle(self, *_args: object, **options: object) -> None: # noqa: PLR0914, PLR0915
|
||||||
"""Download Twitch box art images for all games."""
|
"""Download Twitch box art images for all games."""
|
||||||
limit_value: object | None = options.get("limit")
|
limit_value: object | None = options.get("limit")
|
||||||
limit: int | None = limit_value if isinstance(limit_value, int) else None
|
limit: int | None = limit_value if isinstance(limit_value, int) else None
|
||||||
|
|
@ -118,6 +119,15 @@ class Command(BaseCommand):
|
||||||
box_art_dir: Path = Path(settings.MEDIA_ROOT) / "games" / "box_art"
|
box_art_dir: Path = Path(settings.MEDIA_ROOT) / "games" / "box_art"
|
||||||
self.stdout.write(self.style.SUCCESS(f"Saved box art to: {box_art_dir}"))
|
self.stdout.write(self.style.SUCCESS(f"Saved box art to: {box_art_dir}"))
|
||||||
|
|
||||||
|
# Convert downloaded images to modern formats (WebP, AVIF)
|
||||||
|
if downloaded > 0:
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.MIGRATE_HEADING(
|
||||||
|
"\nConverting downloaded images to modern formats...",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
call_command("convert_images_to_modern_formats")
|
||||||
|
|
||||||
def _convert_to_modern_formats(self, image_path: str) -> None:
|
def _convert_to_modern_formats(self, image_path: str) -> None:
|
||||||
"""Convert downloaded image to WebP and AVIF formats.
|
"""Convert downloaded image to WebP and AVIF formats.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from urllib.parse import urlparse
|
||||||
import httpx
|
import httpx
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
from django.core.management import call_command
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
@ -112,6 +113,15 @@ class Command(BaseCommand):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Convert downloaded images to modern formats (WebP, AVIF)
|
||||||
|
if total_stats["downloaded"] > 0:
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.MIGRATE_HEADING(
|
||||||
|
"\nConverting downloaded images to modern formats...",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
call_command("convert_images_to_modern_formats")
|
||||||
|
|
||||||
def _download_campaign_images(
|
def _download_campaign_images(
|
||||||
self,
|
self,
|
||||||
client: httpx.Client,
|
client: httpx.Client,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue