From 674e0db0653bbb984d052408336edcff25713b30 Mon Sep 17 00:00:00 2001 From: JoeamAmier Date: Fri, 1 Sep 2023 19:41:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/__init__.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/source/__init__.py b/source/__init__.py index f6a6887..86e8675 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -30,32 +30,43 @@ class XHS: self.image = Image() self.video = Video() self.explore = Explore() - self.download = Download(self.manager, path, folder, self.headers, proxies, chunk) + self.download = Download( + self.manager, + path, + folder, + self.headers, + proxies, + chunk) - def get_image(self, container: dict, html: str, download): + def __get_image(self, container: dict, html: str, download): urls = self.image.get_image_link(html) if download: - self.download.run(urls, container["作品ID"]) + self.download.run(urls, self.__naming_rules(container)) container["下载地址"] = urls - def get_video(self, container: dict, html: str, download): + def __get_video(self, container: dict, html: str, download): url = self.video.get_video_link(html) if download: - self.download.run(url, container["作品ID"]) + self.download.run(url, self.__naming_rules(container)) container["下载地址"] = url def extract(self, url: str, download=False) -> dict: - if not self.check(url): + if not self.__check(url): return {} html = self.html.get_html(url) if not html: return {} data = self.explore.run(html) if data["作品类型"] == "视频": - self.get_video(data, html, download) + self.__get_video(data, html, download) else: - self.get_image(data, html, download) + self.__get_image(data, html, download) return data - def check(self, url: str): + def __check(self, url: str): return self.links.match(url) + + @staticmethod + def __naming_rules(data: dict) -> str: + """下载文件默认使用作品 ID 作为文件名,可修改此方法自定义文件名格式""" + return data["作品ID"]