verify youtube thumbnail size
This commit is contained in:
		@@ -209,11 +209,8 @@ class UpstreamHandler():
 | 
			
		||||
                text_upstream_future = resp_upstream.text()
 | 
			
		||||
                text_embed = await text_embed_future
 | 
			
		||||
                text_upstream = await text_upstream_future
 | 
			
		||||
                
 | 
			
		||||
                parser = MetaParser()
 | 
			
		||||
                parser.feed(text_upstream)
 | 
			
		||||
                data_upstream = parser.meta_data
 | 
			
		||||
 | 
			
		||||
                data_raw = json.loads(text_embed)
 | 
			
		||||
                if isinstance(data_raw, dict):
 | 
			
		||||
                    data_new = {}
 | 
			
		||||
@@ -225,11 +222,12 @@ class UpstreamHandler():
 | 
			
		||||
                    data_new["og:video:width"] = data_raw.get("width")
 | 
			
		||||
                    data_new["og:image:height"] = data_raw.get("thumbnail_height")
 | 
			
		||||
                    data_new["og:image:width"] = data_raw.get("thumbnail_width")
 | 
			
		||||
                    data_filtered = data_upstream
 | 
			
		||||
                    data_filtered = {}
 | 
			
		||||
                    for key in data_new:
 | 
			
		||||
                        value = data_new.get(key)
 | 
			
		||||
                        if isinstance(value, str):
 | 
			
		||||
                            data_filtered[key] = value
 | 
			
		||||
                    data_filtered.update(parser.meta_data)
 | 
			
		||||
                    data = data_filtered
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            logger.info(e)
 | 
			
		||||
@@ -367,11 +365,21 @@ class MainHandler(tornado.web.RequestHandler):
 | 
			
		||||
        if handler.provider == "nextcloud":
 | 
			
		||||
            upstream = handler.upstream + "/download"
 | 
			
		||||
        else:
 | 
			
		||||
            if not redir:
 | 
			
		||||
                meta = await handler.meta()
 | 
			
		||||
                image = meta.get("og:image")
 | 
			
		||||
                if isinstance(image, str):
 | 
			
		||||
                if handler.provider == "youtube" and image.endswith("hqdefault.jpg"):
 | 
			
		||||
                    image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
 | 
			
		||||
                    if handler.provider == "youtube":
 | 
			
		||||
                        full_image = None
 | 
			
		||||
                        image_type = None
 | 
			
		||||
                        if image.endswith("hqdefault.jpg"):
 | 
			
		||||
                            full_image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
 | 
			
		||||
                        elif image.endswith("hqdefault.webp"):
 | 
			
		||||
                            full_image = image.removesuffix("hqdefault.webp") + "maxresdefault.webp"
 | 
			
		||||
                        if isinstance(full_image, str):
 | 
			
		||||
                            image_type = await handler.proxy.content_type(full_image)
 | 
			
		||||
                        if isinstance(image_type, str) and image_type.startswith("image"):
 | 
			
		||||
                            image = full_image
 | 
			
		||||
                    image = await handler.proxy.proxy_url(image, None)
 | 
			
		||||
                if isinstance(image, str):
 | 
			
		||||
                    self.set_header("Custom-Poster", image)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user