From 59401dc5bc0adf0386e0efd3ae59f42ba1be8626 Mon Sep 17 00:00:00 2001 From: txperl Date: Mon, 25 Jan 2021 18:37:53 +0800 Subject: [PATCH] [release] 2.0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 macOS 代理自动检测 - 新增 重名文件(夹)判断 - 优化 core 实例化方式 --- README.md | 6 +-- app/core/biu/main.py | 60 ++++++++++++++++++++--------- app/platform.py | 12 ++---- app/plugin/biu/do/dl.py | 34 ++++++++++++---- config.yml | 4 +- usr/templates/multiverse/index.html | 2 +- 6 files changed, 77 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 6e2cb6b..c0d7cd2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ PixivBiu 是一款不错的 Pixiv 搜索**辅助**工具。 * Pixiv 搜索,可免会员按收藏数排序 * 下载原始图片,包括插画、漫画、动图 -* 多种下载模式,自身的单线程、多线程以及 aria2 支持 +* 多种下载模式,单、多线程模式以及 aria2 支持 * 获取用户的作品、收藏夹、关注列表、相关推荐等 * 获取排行榜,包括今日、本周、本月排行等 * 收藏作品、关注等 @@ -27,11 +27,11 @@ PixivBiu 是一款不错的 Pixiv 搜索**辅助**工具。 ### 已编译程序 -此项目基于 `Python@3.7` 编写,使用 `PyInstaller@4.1` 构建编译版本。 +此项目基于 `Python@3.7(+)` 编写,使用 `PyInstaller` 构建编译版本。 这里只提供 Windows 和 macOS 的编译版本,如有其他需求请自行编译。 -具体可在 [Releases](https://github.com/txperl/PixivBiu/releases) 中下载(暂无),或者[在这](https://biu.tls.moe/#/lib/dl)下载。 +具体可在 [Releases](https://github.com/txperl/PixivBiu/releases) 中下载,或者[在这](https://biu.tls.moe/#/lib/dl)下载。 ## 文档 diff --git a/app/core/biu/main.py b/app/core/biu/main.py index c36134e..d5c721a 100644 --- a/app/core/biu/main.py +++ b/app/core/biu/main.py @@ -3,6 +3,7 @@ import os import re import sys +import platform import telnetlib import threading from concurrent.futures import ThreadPoolExecutor @@ -20,9 +21,10 @@ @CMDProcessor.core_register_auto("biu", {"config": "{ROOTPATH}config.yml"}) class core_module_biu(object): def __init__(self, info=None): - self.ver = 200008 + self.ver = 200009 self.lowestConfVer = 3 self.place = "local" + self.sysPlc = platform.system() self.apiType = "public" self.api = None self.apiAssist = None @@ -82,7 +84,7 @@ def __getSystemProxy(self): """ 检测系统本地设置中的代理地址,并验证是否可用。 @Windows: 通过注册表项获取 - @macOS: 暂时未实现 + @macOS: 通过 scutil 获取 @Linux: 暂时未实现 """ if self.sets["biu"]["common"]["proxy"] == "no": @@ -92,28 +94,48 @@ def __getSystemProxy(self): return self.sets["biu"]["common"]["proxy"] proxies = [] + cmd = "" - if os.name == "nt": - tmp = os.popen( - 'reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | findstr "ProxyServer AutoConfigURL"' - ) - oriProxy = tmp.read() - tmp.close() - t = oriProxy.split("\n")[:-1] - proxies = [re.split("\s+", x)[1:] for x in t] + if self.sysPlc == "Windows": + cmd = 'reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | findstr "ProxyServer AutoConfigURL"' + elif self.sysPlc == "Darwin": + cmd = "scutil --proxy" else: - # MBP 不在身边,之后再更新...(( - pass + return "" + + # 获取系统 console 执行结果 + cmdRstObj = os.popen(cmd) + cmdRst = cmdRstObj.read() + cmdRstObj.close() + cmdRstArr = cmdRst.split("\n")[:-1] + proxies = [re.split("\s+", x)[1:] for x in cmdRstArr] # 筛选出可用代理地址 - for x in proxies: - proxy = x[2] - t = re.match(r"https?:\/\/(.*?):(\d+)", proxy) - if t: + for i in range(len(proxies) - 1, -1, -1): + x = proxies[i] + if len(x) < 3: + continue + add = prt = None + + if self.sysPlc == "Windows": + tmp = re.match(r"https?:\/\/(.*?):(\d+)", x[2], re.IGNORECASE) + if tmp is None: + continue + add = tmp.group(1) + prt = int(tmp.group(2)) + elif self.sysPlc == "Darwin": + tmp = re.match(r"https?proxy", x[0], re.IGNORECASE) + if tmp is None: + continue + add = proxies[i][2] + prt = int(proxies[i - 1][2]) + + # 检测本地是否可通 + if add and prt: try: - telnetlib.Telnet(t.group(1), port=int(t.group(2)), timeout=1) - print("[pixivbiu] 已启用系统代理地址: %s" % proxy) - return proxy + telnetlib.Telnet(add, port=prt, timeout=1) + print("[pixivbiu] 已启用系统代理地址: %s" % f"http://{add}:{prt}") + return f"http://{add}:{prt}" except: pass diff --git a/app/platform.py b/app/platform.py index a2f38f6..8448329 100644 --- a/app/platform.py +++ b/app/platform.py @@ -11,17 +11,14 @@ class CMDProcessor(object): PLUGINS = {} - CORES_LIST = [] + + def __init__(self): + self.ENVIRON = ENVIRON def process(self, cmd): if cmd not in self.PLUGINS.keys(): return {"code": 0, "msg": "no method"} - for core in self.CORES_LIST: - fun = getattr(self, core)() - setattr(self, core, fun) - self.ENVIRON = ENVIRON - try: r = self.PLUGINS[cmd](self).pRun(cmd) return r @@ -43,8 +40,7 @@ def wrapper(plugin): @classmethod def core_register(cls, core_name): def wrapper(core): - setattr(cls, core_name, core) - cls.CORES_LIST.append(core_name) + setattr(cls, core_name, core()) return core return wrapper diff --git a/app/plugin/biu/do/dl.py b/app/plugin/biu/do/dl.py index 735148e..7b98e3b 100644 --- a/app/plugin/biu/do/dl.py +++ b/app/plugin/biu/do/dl.py @@ -2,6 +2,7 @@ import json import os import re +import time from ....platform import CMDProcessor @@ -44,7 +45,7 @@ def dl(self, opsArg, funArg): self.code = 0 return "only support illustration, manga and ugoira" - isSingle = len(r["meta_pages"]) is 0 + isSingle = len(r["meta_pages"]) == 0 rootURI = ( self.MOD.biu.sets["biu"]["download"]["saveURI"] .replace("{ROOTPATH}", self.MOD.ENVIRON["ROOTPATH"]) @@ -66,27 +67,41 @@ def dl(self, opsArg, funArg): url = r["meta_single_page"]["original_image_url"].replace( "https://i.pximg.net", self.MOD.biu.pximgURL ) + suf = r["meta_single_page"]["original_image_url"].split(".")[-1] + wholeTitle = picTitle + "." + suf + # 重名文件判断 + if os.path.exists(rootURI + wholeTitle): + wholeTitle = f"{picTitle}_{int(time.time())}.{suf}" status.append( - self.getTemp(url, rootURI, picTitle + "." + r["meta_single_page"]["original_image_url"].split(".")[-1])) + self.getTemp(url, rootURI, wholeTitle)) elif r["type"] != "ugoira" and not isSingle: # 多图下载 index = 0 # 判断是否自动归档 if self.MOD.biu.sets["biu"]["download"]["autoArchive"]: ext = picTitle + "/" + # 重名文件夹判断 + if os.path.exists(rootURI + ext): + ext = f"{picTitle}_{int(time.time())}/" else: ext = "" for x in r["meta_pages"]: picURL = x["image_urls"]["original"] url = picURL.replace("https://i.pximg.net", self.MOD.biu.pximgURL) + suf = picURL.split(".")[-1] + wholeTitle = f"{picTitle}_{str(index)}.{suf}" status.append( - self.getTemp(url, rootURI + ext, picTitle + "_" + str(index) + "." + picURL.split(".")[-1]) + self.getTemp(url, rootURI + ext, wholeTitle) ) index = index + 1 else: # 动图下载 zipUrl, r_ = self.__getdlUgoiraPicsUrl(r["id"]) - temp = self.getTemp(zipUrl, rootURI + picTitle, "ugoira.zip", self.__callback_merge) + wholePath = rootURI + picTitle + # 重名文件夹判断 + if os.path.exists(wholePath): + wholePath = f"{rootURI}{picTitle}_{int(time.time())}" + temp = self.getTemp(zipUrl, wholePath, "ugoira.zip", self.__callback_merge) temp["dlArgs"]["@ugoira"] = { "r": r_, "name": picTitle @@ -154,12 +169,15 @@ def __callback_merge(self, this): pl.append(os.path.join(this._dlSaveDir, "./data", x["file"])) dl.append(x["delay"]) try: - self.MOD.file.unzip(os.path.join(this._dlSaveDir, "./data"), os.path.join(this._dlSaveDir, "ugoira.zip")) + self.MOD.file.unzip(os.path.join(this._dlSaveDir, "./data"), + os.path.join(this._dlSaveDir, "ugoira.zip")) self.MOD.file.rm(os.path.join(this._dlSaveDir, "ugoira.zip")) if self.MOD.biu.sets["biu"]["download"]["whatsUgoira"] == "gif": - self.MOD.file.cov2gif(os.path.join(this._dlSaveDir, this._dlArgs["@ugoira"]["name"] + ".gif"), pl, dl) + self.MOD.file.cov2gif(os.path.join(this._dlSaveDir, this._dlArgs["@ugoira"]["name"] + ".gif"), pl, + dl) else: - self.MOD.file.cov2webp(os.path.join(this._dlSaveDir, this._dlArgs["@ugoira"]["name"] + ".webp"), pl, dl) + self.MOD.file.cov2webp(os.path.join(this._dlSaveDir, this._dlArgs["@ugoira"]["name"] + ".webp"), pl, + dl) except: return False - return True \ No newline at end of file + return True diff --git a/config.yml b/config.yml index 1462a92..05c31fb 100644 --- a/config.yml +++ b/config.yml @@ -38,8 +38,8 @@ biu: proxy: "" # 本地代理服务器监听地址 # 如 http://127.0.0.1:1080/ - # 留空则程序会自动检测系统代理设置(暂时仅支持 Windows) - # 填入 no 则不使用任何代理(暂时仅支持 Windows) + # 留空则程序会自动检测系统代理设置(仅 Windows、macOS) + # 填入 no 则不使用任何代理 defaultActionType: "public" # 账号默认操作类型 diff --git a/usr/templates/multiverse/index.html b/usr/templates/multiverse/index.html index 37657b9..fabcab3 100644 --- a/usr/templates/multiverse/index.html +++ b/usr/templates/multiverse/index.html @@ -118,7 +118,7 @@

搜索

-

PixivBiu@2.0.0b7

+

PixivBiu@2.0.0

一款不错的 Pixiv 搜索辅助工具。
基于 Python 构建。