From 10a09b4c0bb416c5d28e88f066dee0b64a8bc4d8 Mon Sep 17 00:00:00 2001 From: JoeanAmier Date: Sun, 22 Dec 2024 15:15:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正英语项目说明 BREAKING CHANGE: 恢复内置延时机制 --- README_EN.md | 22 ++++++++++++++++++-- source/application/app.py | 13 ++++++------ source/application/download.py | 37 +++++++++++++++++----------------- source/application/explore.py | 4 +++- source/module/tools.py | 11 +++++----- static/Release_Notes.md | 2 +- 6 files changed, 53 insertions(+), 36 deletions(-) diff --git a/README_EN.md b/README_EN.md index fa924ba..57d8cdb 100644 --- a/README_EN.md +++ b/README_EN.md @@ -283,8 +283,8 @@ async def example(): name_format str -Format for content file names. Separate fields with spaces. Supported fields: collects, comments, shares, likes, tags, ID, title, description, type, publish_time, last_update_time, author_nickname, author_id -publish_time author_nickname title +1Format of works file name, separated by spaces between fields, supports fields: 收藏数量评论数量分享数量点赞数量作品标签作品ID作品标题作品描述作品类型发布时间最后更新时间作者昵称作者ID +发布时间 作者昵称 作品标题 user_agent @@ -372,6 +372,24 @@ async def example(): +
+

name_format instructions (Currently only supports Chinese values) :

+ +

Additional Notes: The parameters user_agent examples are provided for reference; Strongly recommend setting according to actual browser information!

🌐 Cookie

diff --git a/source/application/app.py b/source/application/app.py index a63929f..e930773 100644 --- a/source/application/app.py +++ b/source/application/app.py @@ -255,13 +255,12 @@ class XHS: if not data: logging(log, _("{0} 提取数据失败").format(i), ERROR) return {} - match data["作品类型"]: - case _("视频"): - self.__extract_video(data, namespace) - case _("图文"): - self.__extract_image(data, namespace) - case _: - data["下载地址"] = [] + if data["作品类型"] == _("视频"): + self.__extract_video(data, namespace) + elif data["作品类型"] == _("图文"): + self.__extract_image(data, namespace) + else: + data["下载地址"] = [] await self.__download_files(data, download, index, log, bar) logging(log, _("作品处理完成:{0}").format(i)) await sleep_time() diff --git a/source/application/download.py b/source/application/download.py index f2a400e..74ac355 100644 --- a/source/application/download.py +++ b/source/application/download.py @@ -71,25 +71,24 @@ class Download: bar, ) -> tuple[Path, list[Any]]: path = self.__generate_path(name) - match type_: - case _("视频"): - tasks = self.__ready_download_video( - urls, - path, - name, - log, - ) - case _("图文"): - tasks = self.__ready_download_image( - urls, - lives, - index, - path, - name, - log, - ) - case _: - raise ValueError + if type_ == _("视频"): + tasks = self.__ready_download_video( + urls, + path, + name, + log, + ) + elif type_ == _("图文"): + tasks = self.__ready_download_image( + urls, + lives, + index, + path, + name, + log, + ) + else: + raise ValueError tasks = [ self.__download( url, diff --git a/source/application/explore.py b/source/application/explore.py index 75fcf3d..4b989a1 100644 --- a/source/application/explore.py +++ b/source/application/explore.py @@ -8,7 +8,9 @@ __all__ = ['Explore'] class Explore: time_format = "%Y-%m-%d_%H:%M:%S" - explore_type = {"video": _("视频"), "normal": _("图文")} + + def __init__(self): + self.explore_type = {"video": _("视频"), "normal": _("图文")} def run(self, data: Namespace) -> dict: return self.__extract_data(data) diff --git a/source/module/tools.py b/source/module/tools.py index 622c611..90824cc 100644 --- a/source/module/tools.py +++ b/source/module/tools.py @@ -1,5 +1,5 @@ -# from asyncio import sleep -# from random import uniform +from asyncio import sleep +from random import uniform from rich import print from rich.text import Text @@ -28,8 +28,7 @@ def logging(log, text, style=INFO): async def sleep_time( - min_time: int | float = 1, - max_time: int | float = 3, + min_time: int | float = 0.5, + max_time: int | float = 1.5, ): - pass - # await sleep(uniform(min_time, max_time)) + await sleep(uniform(min_time, max_time)) diff --git a/static/Release_Notes.md b/static/Release_Notes.md index 93e0c17..0557a07 100644 --- a/static/Release_Notes.md +++ b/static/Release_Notes.md @@ -7,4 +7,4 @@ 5. 重构项目翻译模块 6. 更正英语语言代码 7. 优化文件下载功能 -8. 移除内置延时机制 +8. 降低内置延时机制