X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/fc8859ef3e192b8e125462ff2cbda0e5dfff3d5d..634e6dfe9359e7cf59849c48ba731a0206b12042:/src/catalogue/utils.py diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index e6e567b8f..60de5556f 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -17,7 +17,6 @@ from zipfile import ZipFile from django.apps import apps from django.conf import settings from django.core.files.storage import DefaultStorage -from django.core.files.uploadedfile import UploadedFile from django.http import HttpResponse from django.utils.encoding import force_str @@ -61,19 +60,6 @@ def split_tags(*tag_lists): return result -class ExistingFile(UploadedFile): - - def __init__(self, path, *args, **kwargs): - self.path = path - super(ExistingFile, self).__init__(*args, **kwargs) - - def temporary_file_path(self): - return self.path - - def close(self): - pass - - class LockFile(object): """ A file lock monitor class; createas an ${objname}.lock @@ -325,11 +311,6 @@ def absolute_url(url): return urljoin(base_url, url) -def get_mp3_length(path): - from mutagen.mp3 import MP3 - return int(MP3(path).info.length) - - def set_file_permissions(self, fieldfile): if fieldfile.instance.preview: fieldfile.set_readable(False) @@ -351,3 +332,14 @@ def iter_file(field_file, chunk_size=CHUNK_SIZE): else: with field_file.open("rb") as f: yield from f.chunks(chunk_size) + + +# TODO: this should be recorded when generated. +ILUSTR_SIZES = [360, 600, 1200, 1800, 2400] +def get_ilustr_sizes(src, slug, index): + ext = src.rsplit('.', 1)[-1] + gallery = absolute_url(gallery_url(slug)) + return { + str(size): f"{gallery}{index}.W{size}.{ext}" + for size in ILUSTR_SIZES + }