25.09.18
parent
c5dd60a82d
commit
3455cb8b50
|
@ -8,7 +8,7 @@ import re
|
|||
import socket
|
||||
import time
|
||||
from typing import Tuple, Optional, Dict
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import urlparse, unquote
|
||||
|
||||
import aiohttp
|
||||
import requests
|
||||
|
@ -199,11 +199,17 @@ class Favicon:
|
|||
_content, _ct = None, None
|
||||
try:
|
||||
# 处理base64编码的图片
|
||||
if self.icon_url.startswith('data:image') and 'base64,' in self.icon_url:
|
||||
if self.icon_url.startswith('data:image'):
|
||||
data_uri = self.icon_url.split(',')
|
||||
if len(data_uri) == 2:
|
||||
_content = base64.b64decode(data_uri[-1])
|
||||
_ct = data_uri[0].split(';')[0].split(':')[-1]
|
||||
if 'svg+xml,' in self.icon_url:
|
||||
_content = unquote(data_uri[-1])
|
||||
elif 'base64,' in self.icon_url:
|
||||
_content = base64.b64decode(data_uri[-1])
|
||||
if ';' in self.icon_url:
|
||||
_ct = data_uri[0].split(';')[0].split(':')[-1]
|
||||
else:
|
||||
_ct = data_uri[0].split(':')[-1]
|
||||
else:
|
||||
_content, _ct = await _req_get(self.icon_url, domain=self.domain)
|
||||
|
||||
|
|
|
@ -131,6 +131,7 @@ default_icon_md5 = [
|
|||
'71e9c45f29eadfa2ec5495302c22bcf6',
|
||||
'ababc687adac587b8a06e580ee79aaa1',
|
||||
'43802bddf65eeaab643adb8265bfbada',
|
||||
'669f77638e6c6eb274ed3ca36827cd72',
|
||||
]
|
||||
|
||||
|
||||
|
@ -329,15 +330,16 @@ async def get_icon_async(entity: Favicon, _cached: bytes = None) -> Optional[byt
|
|||
|
||||
# 尝试不同的图标获取策略
|
||||
strategies = [
|
||||
# 1. 从原始网页标签链接中获取
|
||||
# 0. 从原始网页标签链接中获取
|
||||
lambda: (icon_url, "原始网页标签") if icon_url else (None, None),
|
||||
# 2. 从 gstatic.cn 接口获取
|
||||
# 从 gstatic.cn 接口获取
|
||||
lambda: (
|
||||
f'https://t3.gstatic.cn/faviconV2?client=SOCIAL&fallback_opts=TYPE,SIZE,URL&type=FAVICON&size=128&url={entity.get_base_url()}',
|
||||
"gstatic接口"),
|
||||
# 3. 从网站默认位置获取
|
||||
# 从网站默认位置获取
|
||||
lambda: ('', "网站默认位置/favicon.ico"),
|
||||
# 4. 从其他api接口获取
|
||||
# 从其他api接口获取
|
||||
lambda: (f'https://favicon.is/{entity.domain}', "第三方API"),
|
||||
lambda: (f'https://ico.kucat.cn/get.php?url={entity.get_base_url()}', "第三方API"),
|
||||
# 99. 最后的尝试,cloudflare workers
|
||||
# lambda: (f'https://favicon.cary.cc/?url={entity.get_base_url()}', "cloudflare"),
|
||||
|
|
Loading…
Reference in New Issue