Skip to content

Commit

Permalink
mix(feat, fix): add filter options and fix errors
Browse files Browse the repository at this point in the history
- 新增 宽高比筛选项
- 新增 排行榜特定日期筛选项
- 新增 筛选状态提示
- 新增 前端排序模式
- 新增 前端 XSS 保护
- 修复 前端可能的因特殊符号所导致的搜索和下载问题
- 优化 部分细节
  • Loading branch information
txperl committed Mar 24, 2022
1 parent ef91e40 commit 45af2e6
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 199 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Created by https://www.gitignore.io/api/linux,macos,python,windows

cache/

### Linux ###
*~

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ PixivBiu 是一款不错的 Pixiv **辅助**工具。

## 基础功能

* Pixiv 搜索,可免会员按收藏数、人气排序
* Pixiv 搜索,可免会员按收藏数、人气、日期排序
* 下载原始图片,包括插画、漫画、动图
* 多种下载模式,单、多线程模式以及 aria2 支持
* 筛选图片的宽高、类型、时间、标签等
* 筛选图片的宽高、宽高比、类型、时间、标签等
* 获取用户的作品、收藏夹、关注列表、相关推荐等
* 获取排行榜,包括今日、本周、本月排行等
* 获取排行榜,包括今日、本周、本月、特定日期的排行等
* 收藏作品、关注等

## 使用
Expand Down
6 changes: 3 additions & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ PixivBiu is a nice Pixiv **assistant** tool.

## Features

* Pixiv searching, sort by favorites and popularity without membership
* Pixiv searching, sort by favorites, popularity and date without membership
* Download original images, including illustrations, comics and motion pictures
* Multiple download modes, single and multi-threaded mode and aria2 support
* Filter image width, height, type, time and tags
* Filter image width, height, scale, type, time and tags
* Get user's works, favorites, followers, related recommendations
* Get rankings, including today's, week's, and month's rankings
* Get rankings, including today's, week's, month's, and specific date's rankings
* Favorite works and followers

## Usage
Expand Down
18 changes: 9 additions & 9 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ PixivBiuはPixivのための**補助的な**ツールです。

## 機能

* お気に入り数(会員の除外可)順や人気順でのPixiv検索
* お気に入り数会員の除外可順や人気順でのPixiv検索
* イラスト/漫画/うごイラを含む画像のオリジナル画質でのダウンロード
* シングル/マルチスレッドや[aria2](https://github.com/aria2/aria2)などでのダウンロード
* 画像の幅、高さ、タイプ、時間、ラベルなどをフィルタリングします
* シングル/マルチスレッドや [aria2](https://github.com/aria2/aria2) などでのダウンロード
* 画像の幅、高さ、アスペクト比、タイプ、時間、ラベルなどをフィルタリングします
* 指定したユーザの投稿作品/ブックマーク/フォロワー/関連するおすすめなどの取得
* 当日/週間/月間別などでのランキングの取得
* 当日/週間/月間/特定の日付別などでのランキングの取得
* ブックマークやフォロー中のユーザなどの取得

## 使い方
Expand All @@ -21,9 +21,9 @@ PixivBiuはPixivのための**補助的な**ツールです。

* 依存ライブラリのインストール: `pip install -r requirements.txt`
* [Flask](https://github.com/pallets/flask), [requests](https://github.com/psf/requests), [PyYAML](https://github.com/yaml/pyyaml), [Pillow](https://github.com/python-pillow/Pillow), [PixivPy](https://github.com/upbit/pixivpy), [PySocks](https://github.com/Anorov/PySocks)
* `./config.yml` の設定 (例: [デフォルトの設定ファイル](./app/config/biu_default.yml))
* `./config.yml` の設定(例:[デフォルトの設定ファイル](./app/config/biu_default.yml)
* 実行: `python main.py`
* 実行中のページを開く (デフォルトのURL: `http://127.0.0.1:4001/`)
* 実行中のページを開くデフォルトのURL: `http://127.0.0.1:4001/`

### 実行バイナリから

Expand All @@ -39,11 +39,11 @@ Windows 版と macOS 版が利用可能ですが、もし必要であれば自

## ドキュメント

現在**使い方とAPI**のドキュメントのみがあります必要に応じて[こちら](https://biu.tls.moe/)をご参照ください。
現在**使い方とAPI**のドキュメントのみがあります必要に応じて[こちら](https://biu.tls.moe/)をご参照ください。

## 貢献

もしこのプロジェクトの開発に参加したいのであれば、お気軽に[開発ドキュメント(中文)](https://biu.tls.moe/#/develop/quickin)をご参照ください。
もしこのプロジェクトの開発に参加したいのであれば、お気軽に[開発ドキュメント(中文)](https://biu.tls.moe/#/develop/quickin)をご参照ください。

## その他

Expand All @@ -55,6 +55,6 @@ Windows 版と macOS 版が利用可能ですが、もし必要であれば自

### 告知事項

* 本プログラム (PixivBiu) は学習と交流のみを目的としておりますので、当初の目的を達成した後は自分で削除してください
* 本プログラムPixivBiuは学習と交流のみを目的としておりますので、当初の目的を達成した後は自分で削除してください
* 使用後の如何なる問題も作者には一切関係なく、また作者は一切の責任を負いません
* [MITライセンス](https://choosealicense.com/licenses/mit/)です
6 changes: 2 additions & 4 deletions app/lib/common/login_helper/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import platform

import requests

from altfe.interface.root import interRoot
from app.lib.common.login_helper.token import tokenGetter


@interRoot.bind("loginHelper", "LIB_COMMON")
class common_loginHelper(interRoot):
class CommonLoginHelper(interRoot):
"""
Pixiv 登陆助手。
可以优先进行网络检测以及筛选,以提高在网络不佳情况下的 Token 获取概率。
Expand Down Expand Up @@ -36,7 +34,7 @@ def check_network(self, URLS=None, silent=False, proxy_="auto"):
"https://doh.dns.sb/dns-query",
"https://cloudflare-dns.com/dns-query",
) if URLS is None else URLS
proxy = self.STATIC.util.getSystemProxy(platform.system()) if proxy_ == "auto" else proxy_
proxy = self.STATIC.util.get_system_proxy() if proxy_ == "auto" else proxy_
if silent is False:
self.STATIC.localMsger.msg(self.lang("network.hint_in_check"), header="Login Helper")
if proxy == "":
Expand Down
6 changes: 3 additions & 3 deletions app/lib/core/biu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@interRoot.bind("biu", "LIB_CORE")
class core_module_biu(interRoot):
def __init__(self):
self.ver = 204000
self.ver = 205000
self.place = "local"
self.sysPlc = platform.system()
self.api_route = "direct"
Expand Down Expand Up @@ -65,7 +65,7 @@ def __pre_check(self):
1. 检测端口是否已被占用
"""
# 检测端口是否被占用
if self.STATIC.util.isPortInUse(self.sets["sys"]["host"].split(":")[1]):
if self.STATIC.util.is_prot_in_use(self.sets["sys"]["host"].split(":")[1]):
self.STATIC.localMsger.red(self.lang("config.hint_port_is_in_use"))
input(self.lang("common.press_to_exit"))
sys.exit(0)
Expand All @@ -79,7 +79,7 @@ def __get_system_proxy(self):
return ""
if self.sets["sys"]["proxy"] != "":
return self.sets["sys"]["proxy"]
proxy_address = self.STATIC.util.getSystemProxy(self.sysPlc)
proxy_address = self.STATIC.util.get_system_proxy(self.sysPlc)
if proxy_address != "":
self.STATIC.localMsger.msg(f"{self.lang('config.hint_proxy_in_use')}: {proxy_address}")
return proxy_address
Expand Down
43 changes: 22 additions & 21 deletions app/lib/static/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import re
import socket
import telnetlib
Expand All @@ -8,65 +9,65 @@


@interRoot.bind("util", "LIB_STATIC")
class util(object):
class StaticUtil(object):
@staticmethod
def getSystemProxy(sysPlc):
def get_system_proxy(sys_plc=None):
"""
检测系统本地设置中的代理地址。
@Windows: 通过注册表项获取
@macOS: 通过 scutil 获取
@Linux: 暂时未实现
"""

if sys_plc is None:
sys_plc = platform.system()
# 命令选择
if sysPlc == "Windows":
if sys_plc == "Windows":
cmd = r'reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | ' \
r'findstr "ProxyServer AutoConfigURL" '
elif sysPlc == "Darwin":
elif sys_plc == "Darwin":
cmd = "scutil --proxy"
else:
return ""

# 获取系统终端执行结果
cmdRstObj = os.popen(cmd)
cmdRst = cmdRstObj.read()
cmdRstObj.close()
cmd_rst_obj = os.popen(cmd)
cmd_rst = cmd_rst_obj.read()
cmd_rst_obj.close()

# 获取代理地址
dic = {}
if sysPlc == "Windows":
if sys_plc == "Windows":
# Windows
for x in [re.split(r"\s+", x)[1:] for x in cmdRst.split("\n")]:
maybe = ["AutoConfigURL", "ProxyServer"]
for x in [re.split(r"\s+", x)[1:] for x in cmd_rst.split("\n")]:
if len(x) != 3:
continue
dic[x[0]] = x[2]
MAY = ["AutoConfigURL", "ProxyServer"]
for key in MAY:
for key in maybe:
if key in dic:
return dic[key]
elif sysPlc == "Darwin":
elif sys_plc == "Darwin":
# macOS
for x in cmdRst.replace(" ", "").split("\n"):
maybe = ["HTTP", "HTTPS", "SOCKS", "ProxyAutoConfig"]
for x in cmd_rst.replace(" ", "").split("\n"):
if ":" not in x:
continue
tmp = x.split(":")
dic[tmp[0]] = ":".join(tmp[1:])
SUP = ["HTTP", "HTTPS", "SOCKS", "ProxyAutoConfig"]
for ptl in SUP:
subKey = f"{ptl}Enable"
if subKey in dic and dic[subKey] == "1":
for ptl in maybe:
subkey = f"{ptl}Enable"
if subkey in dic and dic[subkey] == "1":
if ptl == "ProxyAutoConfig":
proxy = dic["ProxyAutoConfigURLString"]
else:
proxy = "%s://%s:%s/" % (
ptl.lower() if ptl != "SOCKS" else "socks5", dic[ptl + "Proxy"], dic[ptl + "Port"]
)
return proxy

return ""

@staticmethod
def isLocalCon(add, prt):
def is_local_connect(add, prt):
# 检测本地是否可通
try:
telnetlib.Telnet(add, port=prt, timeout=1)
Expand All @@ -75,7 +76,7 @@ def isLocalCon(add, prt):
return False

@staticmethod
def isPortInUse(port):
def is_prot_in_use(port):
port = int(port)
if port >= 0 and port <= 65535:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand Down
5 changes: 4 additions & 1 deletion app/plugin/get/rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ class getRank(interRoot):
def run(self, cmd):
try:
args = self.STATIC.arg.getArgs(
"rank", ["mode=day", "&totalPage=5", "&groupIndex=0"]
"rank", ["mode=day", "date=0", "&totalPage=5", "&groupIndex=0"]
)
except:
return {"code": 0, "msg": "missing parameters"}

if len(str(args["fun"]["date"]).split("-")) != 3:
args["fun"]["date"] = None

return {
"code": 1,
"msg": {
Expand Down
40 changes: 11 additions & 29 deletions app/plugin/search/works.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from concurrent.futures import as_completed

from altfe.interface.root import interRoot
Expand All @@ -15,47 +16,28 @@ def run(self, cmd):
"&totalPage=5",
"&groupIndex=0",
"&sortMode=0",
"&isSort=1",
"&isSort=0",
"&isCache=1",
],
)
except:
return {"code": 0, "msg": "missing parameters"}

code = 1

isCache = (
int(args["ops"]["isCache"])
and self.CORE.biu.sets["biu"]["search"]["loadCacheFirst"]
)

isCache = int(args["ops"]["isCache"]) and self.CORE.biu.sets["biu"]["search"]["loadCacheFirst"]
cachePath = self.getENV("rootPath") + "usr/cache/data_search/"
fileName = (
(
"%s@%s_%sx%s_%s%s.json"
% (
args["fun"]["kt"],
args["fun"]["mode"],
args["ops"]["totalPage"],
args["ops"]["groupIndex"],
args["ops"]["sortMode"],
args["ops"]["isSort"],
)
)
.replace("\\", "#")
.replace("/", "#")
.replace(":", "#")
.replace("*", "#")
.replace("?", "#")
.replace('"', "#")
.replace("<", "#")
.replace(">", "#")
.replace("|", "#")
fileName = "%s@%s_%sx%s_%s%s.json" % (
args["fun"]["kt"],
args["fun"]["mode"],
args["ops"]["totalPage"],
args["ops"]["groupIndex"],
args["ops"]["sortMode"],
args["ops"]["isSort"],
)
fileName = re.sub(r'[/\\:*?"<>|]', "_", fileName)

if isCache:
isCacheFile = self.STATIC.file.ain(cachePath + fileName)

if isCache and isCacheFile:
rst = isCacheFile
code = 2
Expand Down
Loading

0 comments on commit 45af2e6

Please sign in to comment.