From 086ff930e11d1b99abd9fb7310d5552eca43314e Mon Sep 17 00:00:00 2001 From: Quan Date: Wed, 7 Jan 2026 19:28:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor(app):=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/app.py | 2 +- source/application/image.py | 14 ++++++++++---- source/application/video.py | 8 ++++++++ source/expansion/converter.py | 25 +++++++++++++++++++------ static/Release_Notes.md | 3 ++- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/source/application/app.py b/source/application/app.py index 2524fe6..ab89e38 100644 --- a/source/application/app.py +++ b/source/application/app.py @@ -199,7 +199,7 @@ class XHS: container: dict, data: Namespace, ): - container["下载地址"] = self.video.get_video_link( + container["下载地址"] = self.video.deal_video_link( data, ) container["动图地址"] = [ diff --git a/source/application/image.py b/source/application/image.py index 30ac4b9..b9b6eea 100644 --- a/source/application/image.py +++ b/source/application/image.py @@ -10,10 +10,16 @@ class Image: def get_image_link(cls, data: Namespace, format_: str) -> tuple[list, list]: images = data.safe_extract("imageList", []) live_link = cls.__get_live_link(images) - token_list = [ - cls.__extract_image_token(Namespace.object_extract(i, "urlDefault")) - for i in images - ] + if not any( + token_list := [ + cls.__extract_image_token(Namespace.object_extract(i, "urlDefault")) + for i in images + ] + ): + token_list = [ + cls.__extract_image_token(Namespace.object_extract(i, "url")) + for i in images + ] match format_: case "png" | "webp" | "jpeg" | "heic" | "avif": return [ diff --git a/source/application/video.py b/source/application/video.py index 1aaa8b5..fa91756 100644 --- a/source/application/video.py +++ b/source/application/video.py @@ -11,6 +11,14 @@ class Video: "originVideoKey", ) + @classmethod + def deal_video_link( + cls, + data: Namespace, + preference="resolution", + ): + return cls.generate_video_link(data) or cls.get_video_link(data, preference) + @classmethod def generate_video_link(cls, data: Namespace) -> list: return ( diff --git a/source/expansion/converter.py b/source/expansion/converter.py index d1e01bd..c77254d 100644 --- a/source/expansion/converter.py +++ b/source/expansion/converter.py @@ -8,12 +8,17 @@ __all__ = ["Converter"] class Converter: INITIAL_STATE = "//script/text()" - KEYS_LINK = ( + PC_KEYS_LINK = ( "note", "noteDetailMap", "[-1]", "note", ) + PHONE_KEYS_LINK = ( + "noteData", + "data", + "noteData", + ) def run(self, content: str) -> dict: return self._filter_object(self._convert_object(self._extract_object(content))) @@ -31,7 +36,11 @@ class Converter: @classmethod def _filter_object(cls, data: dict) -> dict: - return cls.deep_get(data, cls.KEYS_LINK) or {} + return ( + cls.deep_get(data, cls.PHONE_KEYS_LINK) + or cls.deep_get(data, cls.PC_KEYS_LINK) + or {} + ) @classmethod def deep_get(cls, data: dict, keys: list | tuple, default=None): @@ -58,7 +67,11 @@ class Converter: @staticmethod def get_script(scripts: list) -> str: scripts.reverse() - for script in scripts: - if script.startswith("window.__INITIAL_STATE__"): - return script - return "" + return next( + ( + script + for script in scripts + if script.startswith("window.__INITIAL_STATE__") + ), + "", + ) diff --git a/static/Release_Notes.md b/static/Release_Notes.md index ee7b9eb..6d4db3e 100644 --- a/static/Release_Notes.md +++ b/static/Release_Notes.md @@ -5,7 +5,8 @@ 3. 新增连接用户脚本下载作品功能 4. 修复视频作品下载功能 5. 新增作品处理统计功能 -6. 调整内置延时机制 +6. 重构数据处理逻辑 +7. 调整内置延时机制 *****