mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
detect missing webp support
This commit is contained in:
parent
374ff3433e
commit
96223fda01
|
@ -14,7 +14,7 @@ from .util import mp
|
||||||
from .authsrv import AuthSrv
|
from .authsrv import AuthSrv
|
||||||
from .tcpsrv import TcpSrv
|
from .tcpsrv import TcpSrv
|
||||||
from .up2k import Up2k
|
from .up2k import Up2k
|
||||||
from .th_srv import ThumbSrv, HAVE_PIL
|
from .th_srv import ThumbSrv, HAVE_PIL, HAVE_WEBP
|
||||||
|
|
||||||
|
|
||||||
class SvcHub(object):
|
class SvcHub(object):
|
||||||
|
@ -47,6 +47,11 @@ class SvcHub(object):
|
||||||
self.thumbsrv = None
|
self.thumbsrv = None
|
||||||
if not args.no_thumb:
|
if not args.no_thumb:
|
||||||
if HAVE_PIL:
|
if HAVE_PIL:
|
||||||
|
if not HAVE_WEBP:
|
||||||
|
args.th_no_webp = True
|
||||||
|
msg = "setting --th-no-webp because either libwebp is not available or your Pillow is too old"
|
||||||
|
self.log("thumb", msg, c=3)
|
||||||
|
|
||||||
self.thumbsrv = ThumbSrv(self, auth.vfs.all_vols)
|
self.thumbsrv = ThumbSrv(self, auth.vfs.all_vols)
|
||||||
else:
|
else:
|
||||||
msg = "need Pillow to create thumbnails; for example:\n {} -m pip install --user Pillow"
|
msg = "need Pillow to create thumbnails; for example:\n {} -m pip install --user Pillow"
|
||||||
|
|
|
@ -21,12 +21,12 @@ class ThumbCli(object):
|
||||||
if self.args.no_vthumb and ext in FMT_FF:
|
if self.args.no_vthumb and ext in FMT_FF:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if fmt == "w" and self.args.th_no_webp:
|
|
||||||
fmt = "j"
|
|
||||||
|
|
||||||
if fmt == "j" and self.args.th_no_jpg:
|
if fmt == "j" and self.args.th_no_jpg:
|
||||||
fmt = "w"
|
fmt = "w"
|
||||||
|
|
||||||
|
if fmt == "w" and self.args.th_no_webp:
|
||||||
|
fmt = "j"
|
||||||
|
|
||||||
tpath = thumb_path(ptop, rem, mtime, fmt)
|
tpath = thumb_path(ptop, rem, mtime, fmt)
|
||||||
ret = None
|
ret = None
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -8,14 +8,13 @@ import threading
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
|
||||||
from .__init__ import PY2
|
from .__init__ import PY2
|
||||||
from .util import fsenc, Queue, Cooldown
|
from .util import fsenc, Queue, Cooldown, BytesIO
|
||||||
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe
|
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe
|
||||||
|
|
||||||
|
|
||||||
if not PY2:
|
if not PY2:
|
||||||
unicode = str
|
unicode = str
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
HAVE_PIL = True
|
HAVE_PIL = True
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
|
@ -27,6 +26,12 @@ try:
|
||||||
register_heif_opener()
|
register_heif_opener()
|
||||||
except:
|
except:
|
||||||
HAVE_HEIF = False
|
HAVE_HEIF = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
Image.new("RGB", (2, 2)).save(BytesIO(), format="webp")
|
||||||
|
HAVE_WEBP = True
|
||||||
|
except:
|
||||||
|
HAVE_WEBP = False
|
||||||
except:
|
except:
|
||||||
HAVE_PIL = False
|
HAVE_PIL = False
|
||||||
|
|
||||||
|
@ -339,7 +344,7 @@ class ThumbSrv(object):
|
||||||
# thumb file
|
# thumb file
|
||||||
try:
|
try:
|
||||||
b64, ts, ext = f.split(".")
|
b64, ts, ext = f.split(".")
|
||||||
if len(b64) != 24 or len(ts) != 8 or ext != "jpg":
|
if len(b64) != 24 or len(ts) != 8 or ext not in ["jpg", "webp"]:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
|
||||||
ts = int(ts, 16)
|
ts = int(ts, 16)
|
||||||
|
|
|
@ -34,10 +34,12 @@ if not PY2:
|
||||||
from urllib.parse import unquote_to_bytes as unquote
|
from urllib.parse import unquote_to_bytes as unquote
|
||||||
from urllib.parse import quote_from_bytes as quote
|
from urllib.parse import quote_from_bytes as quote
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
from io import BytesIO
|
||||||
else:
|
else:
|
||||||
from urllib import unquote # pylint: disable=no-name-in-module
|
from urllib import unquote # pylint: disable=no-name-in-module
|
||||||
from urllib import quote # pylint: disable=no-name-in-module
|
from urllib import quote # pylint: disable=no-name-in-module
|
||||||
from Queue import Queue # pylint: disable=import-error,no-name-in-module
|
from Queue import Queue # pylint: disable=import-error,no-name-in-module
|
||||||
|
from StringIO import StringIO as BytesIO
|
||||||
|
|
||||||
surrogateescape.register_surrogateescape()
|
surrogateescape.register_surrogateescape()
|
||||||
FS_ENCODING = sys.getfilesystemencoding()
|
FS_ENCODING = sys.getfilesystemencoding()
|
||||||
|
|
Loading…
Reference in a new issue