diff --git a/source/application/app.py b/source/application/app.py index 7ed79b2..2524fe6 100644 --- a/source/application/app.py +++ b/source/application/app.py @@ -194,8 +194,14 @@ class XHS: data, self.manager.image_format ) - def __extract_video(self, container: dict, data: Namespace): - container["下载地址"] = self.video.get_video_link(data) + def __extract_video( + self, + container: dict, + data: Namespace, + ): + container["下载地址"] = self.video.get_video_link( + data, + ) container["动图地址"] = [ None, ] diff --git a/source/application/video.py b/source/application/video.py index 678b819..1aaa8b5 100644 --- a/source/application/video.py +++ b/source/application/video.py @@ -12,9 +12,32 @@ class Video: ) @classmethod - def get_video_link(cls, data: Namespace) -> list: + def generate_video_link(cls, data: Namespace) -> list: return ( [Html.format_url(f"https://sns-video-bd.xhscdn.com/{t}")] if (t := data.safe_extract(".".join(cls.VIDEO_LINK))) else [] ) + + @classmethod + def get_video_link( + cls, + data: Namespace, + preference="resolution", + ) -> list: + if not (items := cls.get_video_items(data)): + return [] + match preference: + case "resolution": + items.sort(key=lambda x: x.height) + case "bitrate" | "size": + items.sort(key=lambda x: x.preference) + case _: + raise ValueError(f"Invalid video preference value: {preference}") + return [b[0]] if (b := items[-1].backupUrls) else [items[-1].masterUrl] + + @staticmethod + def get_video_items(data: Namespace) -> list: + h264 = data.safe_extract("video.media.stream.h264") + h265 = data.safe_extract("video.media.stream.h265") + return [*h264, *h265] diff --git a/static/Release_Notes.md b/static/Release_Notes.md index ab32f06..5c14e9f 100644 --- a/static/Release_Notes.md +++ b/static/Release_Notes.md @@ -3,8 +3,9 @@ 1. 修复 MCP 模式无法下载文件的问题 2. 新增 `script_server` 配置参数 3. 新增连接用户脚本下载作品功能 -4. 新增作品处理统计功能 -5. 调整内置延时机制 +4. 修复视频作品下载功能 +5. 新增作品处理统计功能 +6. 调整内置延时机制 *****