fix: support spaced emoji media attributes

This commit is contained in:
liuwei
2026-04-13 12:21:06 +08:00
parent 45d97b2989
commit 7ee5ba93ab
6 changed files with 14 additions and 9 deletions

View File

@@ -36,7 +36,11 @@ def _is_usable_local_media_path(value: str) -> bool:
def _extract_emoji_preview_url(xml_text: str) -> str:
if not xml_text:
return ''
patterns = (r'cdnurl="([^"]+)"', r'encrypturl="([^"]+)"', r'externurl="([^"]+)"')
patterns = (
r'cdnurl\s*=\s*"([^"]+)"',
r'encrypturl\s*=\s*"([^"]+)"',
r'externurl\s*=\s*"([^"]+)"'
)
for pattern in patterns:
match = re.search(pattern, xml_text)
if match:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
temp/test_emoji_extract.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -60,14 +60,15 @@ class MessageStorage:
self._image_loop = asyncio.new_event_loop()
# 正则(替代 XML 解析)
self._aeskey_re = re.compile(r'aeskey="(.*?)"')
self._cdn_re = re.compile(r'cdnthumburl="(.*?)"')
self._cdn_mid_re = re.compile(r'cdnmidimgurl="(.*?)"')
self._cdn_big_re = re.compile(r'cdnbigimgurl="(.*?)"')
self._emoji_cdn_re = re.compile(r'cdnurl="(.*?)"')
self._emoji_encrypt_re = re.compile(r'encrypturl="(.*?)"')
self._emoji_extern_re = re.compile(r'externurl="(.*?)"')
self._md5_re = re.compile(r'md5="(.*?)"')
attr = r'\s*=\s*["\'](.*?)["\']'
self._aeskey_re = re.compile(rf'aeskey{attr}')
self._cdn_re = re.compile(rf'cdnthumburl{attr}')
self._cdn_mid_re = re.compile(rf'cdnmidimgurl{attr}')
self._cdn_big_re = re.compile(rf'cdnbigimgurl{attr}')
self._emoji_cdn_re = re.compile(rf'cdnurl{attr}')
self._emoji_encrypt_re = re.compile(rf'encrypturl{attr}')
self._emoji_extern_re = re.compile(rf'externurl{attr}')
self._md5_re = re.compile(rf'md5{attr}')
# 修改为项目根目录下的 static/images
self.image_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "static", "images")