Skip to content

Commit

Permalink
[release] 2.0.0
Browse files Browse the repository at this point in the history
- 新增 macOS 代理自动检测
- 新增 重名文件(夹)判断
- 优化 core 实例化方式
  • Loading branch information
txperl committed Jan 25, 2021
1 parent 11477d7 commit 59401dc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 41 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PixivBiu 是一款不错的 Pixiv 搜索**辅助**工具。

* Pixiv 搜索,可免会员按收藏数排序
* 下载原始图片,包括插画、漫画、动图
* 多种下载模式,自身的单线程、多线程以及 aria2 支持
* 多种下载模式,单、多线程模式以及 aria2 支持
* 获取用户的作品、收藏夹、关注列表、相关推荐等
* 获取排行榜,包括今日、本周、本月排行等
* 收藏作品、关注等
Expand All @@ -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)下载。

## 文档

Expand Down
60 changes: 41 additions & 19 deletions app/core/biu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import sys
import platform
import telnetlib
import threading
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -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
Expand Down Expand Up @@ -82,7 +84,7 @@ def __getSystemProxy(self):
"""
检测系统本地设置中的代理地址,并验证是否可用。
@Windows: 通过注册表项获取
@macOS: 暂时未实现
@macOS: 通过 scutil 获取
@Linux: 暂时未实现
"""
if self.sets["biu"]["common"]["proxy"] == "no":
Expand All @@ -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

Expand Down
12 changes: 4 additions & 8 deletions app/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 26 additions & 8 deletions app/plugin/biu/do/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import re
import time

from ....platform import CMDProcessor

Expand Down Expand Up @@ -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"])
Expand All @@ -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
Expand Down Expand Up @@ -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
return True
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ biu:
proxy: ""
# 本地代理服务器监听地址
# 如 http://127.0.0.1:1080/
# 留空则程序会自动检测系统代理设置(暂时仅支持 Windows)
# 填入 no 则不使用任何代理(暂时仅支持 Windows)
# 留空则程序会自动检测系统代理设置( Windows、macOS
# 填入 no 则不使用任何代理

defaultActionType: "public"
# 账号默认操作类型
Expand Down
2 changes: 1 addition & 1 deletion usr/templates/multiverse/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ <h2>搜索</h2>
<div class="inner split">
<div>
<section>
<h2>PixivBiu@2.0.0b7</h2>
<h2>PixivBiu@2.0.0</h2>
<p>一款不错的 Pixiv 搜索<b>辅助</b>工具。<br>基于 Python 构建。</p>
</section>
<section>
Expand Down

0 comments on commit 59401dc

Please sign in to comment.