Index: channels/favicon.py ================================================================== --- channels/favicon.py +++ channels/favicon.py @@ -7,11 +7,11 @@ # { name: favicon_delete_stub , type: bool, value: 1, description: "Don't accept any placeholder favicons." } # [ main-name: google_homepage ] # [ main-name: load_favicon ] # type: feature # category: ui -# version: 1.7 +# version: 1.8 # depends: streamtuner2 >= 2.1.9, python:pil # priority: standard # # This module fetches a favicon for each station, or a small banner # or logo for some channel modules. It converts .ico image files and @@ -23,18 +23,20 @@ # # While it can often discover favicons directly from station homepages, # it's often speedier to use the Google PNG conversion service. Both # depend on a recent Pillow2 python module (superseding the PIL module). # Else may display images with fragments if converted from ICO files. + import os, os.path from io import BytesIO import re from config import * import ahttp from PIL import Image from uikit import gtk +#import traceback # Ensure that we don't try to download a single favicon twice per session. # If it's not available the first time, we won't get it after switching # stations back and forth either. So URLs are skipped simply. @@ -247,22 +249,26 @@ # Convert accepted formats -- even PNG for filtering now if re.match(br'^(.PNG|GIF\d+|.{0,15}JFIF|\x00\x00\x01\x00|.{0,255}]+svg)', imgdata): try: # Read from byte/str image = Image.open(BytesIO(imgdata)) - log.FAVICON_IMAGE_TO_PNG(image, resize) + log.FAVICON_IMAGE_TO_PNG(image, image.size, resize) # Resize if resize and image.size[0] > resize: - image.resize((resize, resize), Image.ANTIALIAS) + try: + image.thumbnail(resize, Image.ANTIALIAS) + except: + image = image.resize((resize,resize), Image.ANTIALIAS) # Convert to PNG via string buffer out = BytesIO() image.save(out, "PNG", quality=98) imgdata = out.getvalue() except Exception as e: + #traceback.print_exc() return log.ERR("favicon/logo conversion error:", e) and False else: log.WARN("Couldn't detect valig image type from its raw content") # PNG already? @@ -327,16 +333,17 @@ for name in ("shortcut icon", "favicon", "icon", "icon shortcut"): if name == pair.get("rel", "ignore").lower() and pair.get("href"): href = pair["href"].replace("&", "&") # unhtml() break # Patch URL together + log.DATA(url, href) if re.match("^https?://", href): # absolute URL return href - elif re.startswith("//", href): # proto-absolute + elif href.startswith("//"): # proto-absolute return "http:" + href - elif re.startswith("/", href): # root path - return re.sub("(https?://[^/]).*$", "\g<1>") + href + elif href.startswith("/"): # root path + return re.sub("(https?://[^/]+).*$", "\g<1>", url) + href else: # relative path references xyz/../ href = re.sub("[^/]+$", "", url) + href return re.sub("[^/]+/../", "/", href)