diff --git a/copyparty/svchub.py b/copyparty/svchub.py index d8769957..c2b192cf 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -14,7 +14,7 @@ from .util import mp from .authsrv import AuthSrv from .tcpsrv import TcpSrv from .up2k import Up2k -from .th_srv import ThumbSrv, HAVE_PIL +from .th_srv import ThumbSrv, HAVE_PIL, HAVE_WEBP class SvcHub(object): @@ -47,6 +47,11 @@ class SvcHub(object): self.thumbsrv = None if not args.no_thumb: 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) else: msg = "need Pillow to create thumbnails; for example:\n {} -m pip install --user Pillow" diff --git a/copyparty/th_cli.py b/copyparty/th_cli.py index 1e49a84a..bf26964e 100644 --- a/copyparty/th_cli.py +++ b/copyparty/th_cli.py @@ -21,12 +21,12 @@ class ThumbCli(object): if self.args.no_vthumb and ext in FMT_FF: return None - if fmt == "w" and self.args.th_no_webp: - fmt = "j" - if fmt == "j" and self.args.th_no_jpg: fmt = "w" + if fmt == "w" and self.args.th_no_webp: + fmt = "j" + tpath = thumb_path(ptop, rem, mtime, fmt) ret = None try: diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 7d6163f8..f918787a 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -8,14 +8,13 @@ import threading import subprocess as sp 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 if not PY2: unicode = str - try: HAVE_PIL = True from PIL import Image, ImageOps @@ -27,6 +26,12 @@ try: register_heif_opener() except: HAVE_HEIF = False + + try: + Image.new("RGB", (2, 2)).save(BytesIO(), format="webp") + HAVE_WEBP = True + except: + HAVE_WEBP = False except: HAVE_PIL = False @@ -339,7 +344,7 @@ class ThumbSrv(object): # thumb file try: 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() ts = int(ts, 16) diff --git a/copyparty/util.py b/copyparty/util.py index b7152e00..35d03c56 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -34,10 +34,12 @@ if not PY2: from urllib.parse import unquote_to_bytes as unquote from urllib.parse import quote_from_bytes as quote from queue import Queue + from io import BytesIO else: from urllib import unquote # 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 StringIO import StringIO as BytesIO surrogateescape.register_surrogateescape() FS_ENCODING = sys.getfilesystemencoding()