From 6dcc979fd5601eaa403e79f6e784aa37663d651e Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 14 Nov 2023 08:19:57 +0800 Subject: [PATCH] fix #1072 fix #1118 --- app/core/plugin.py | 3 +++ app/helper/rss.py | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/core/plugin.py b/app/core/plugin.py index a2475d94..872ecde3 100644 --- a/app/core/plugin.py +++ b/app/core/plugin.py @@ -12,6 +12,7 @@ from app.schemas.types import SystemConfigKey from app.utils.object import ObjectUtils from app.utils.singleton import Singleton from app.utils.string import StringUtils +from app.utils.system import SystemUtils class PluginManager(metaclass=Singleton): @@ -105,6 +106,8 @@ class PluginManager(metaclass=Singleton): """ 安装本地不存在的在线插件 """ + if SystemUtils.is_frozen(): + return logger.info("开始安装在线插件...") # 已安装插件 install_plugins = self.systemconfig.get(SystemConfigKey.UserInstalledPlugins) or [] diff --git a/app/helper/rss.py b/app/helper/rss.py index 957e5314..cd328220 100644 --- a/app/helper/rss.py +++ b/app/helper/rss.py @@ -1,11 +1,14 @@ +import re import xml.dom.minidom from typing import List, Tuple, Union from urllib.parse import urljoin +import chardet from lxml import etree from app.core.config import settings from app.helper.browser import PlaywrightHelper +from app.log import logger from app.utils.dom import DomUtils from app.utils.http import RequestUtils from app.utils.string import StringUtils @@ -240,8 +243,28 @@ class RssHelper: print(str(err)) return [] if ret: - ret_xml = ret.text + ret_xml = "" try: + # 使用chardet检测字符编码 + raw_data = ret.content + if raw_data: + try: + result = chardet.detect(raw_data) + encoding = result['encoding'] + # 解码为字符串 + ret_xml = raw_data.decode(encoding) + except Exception as e: + logger.debug(f"chardet解码失败:{str(e)}") + # 探测utf-8解码 + match = re.search(r'encoding\s*=\s*["\']([^"\']+)["\']', ret.text) + if match: + encoding = match.group(1) + if encoding: + ret_xml = raw_data.decode(encoding) + else: + ret.encoding = ret.apparent_encoding + if not ret_xml: + ret_xml = ret.text # 解析XML dom_tree = xml.dom.minidom.parseString(ret_xml) rootNode = dom_tree.documentElement