Skip to content

Commit

Permalink
2.022 cache webui locally
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Mar 23, 2020
1 parent ec9c522 commit a79c4c3
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ make.bat
config.py
README.html
CHANGELOG.html
webui.gz
11 changes: 7 additions & 4 deletions README.chs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ xeH
- **download_ori** 是否下载原图,默认为否
- **jpn_title** 是否使用日语标题,如果关闭则使用英文或罗马字标题,默认为是
- **rename_ori** 将图片重命名为原始名称,如果关闭则使用序号,默认为否
- **make_archive** 是否下载完成后生成zip压缩包,并删除下载目录,默认为否

高级参数:

Expand All @@ -47,7 +48,6 @@ xeH
- **rpc_port** RPC绑定的端口,默认为`None`
- **rpc_secret** RPC密钥,默认为`None` (不开启RPC服务器)
- **delete_task_files** 是否删除任务时同时删除下载的文件,默认为否
- **make_archive** 是否下载完成后生成zip压缩包,并删除下载目录,默认为否
- **download_range** 设置下载的图片范围,参见[下载范围](#下载范围)
- **scan_thread_cnt** 扫描线程数,默认为`1`
- **download_thread_cnt** 下载线程数,默认为`5`
Expand All @@ -64,9 +64,10 @@ xeH
用法: xeH [-u USERNAME] [-k KEY] [-c COOKIE] [-i] [--daemon] [-d DIR] [-o]
[-j BOOL] [-r BOOL] [-p PROXY] [--proxy-image | --proxy-image-only]
[--rpc-interface ADDR] [--rpc-port PORT] [--rpc-secret ...]
[--delete-task-files BOOL] [-a BOOL] [--download-range a-b,c-d,e]
[-t N] [--timeout N] [--low-speed-threshold N] [-f]
[-l /path/to/eh.log] [-v] [-h] [--version]
[--rpc-open-browser BOOL] [--delete-task-files BOOL] [-a BOOL]
[--download-range a-b,c-d,e] [-t N] [--timeout N]
[--low-speed-threshold N] [-f] [-l /path/to/eh.log] [-v] [-h]
[--version]
[url [url ...]]
绅♂士下载器
Expand Down Expand Up @@ -96,6 +97,8 @@ xeH
--rpc-interface ADDR 设置JSON-RPC监听IP (默认: localhost)
--rpc-port PORT 设置JSON-RPC监听端口 (默认: None)
--rpc-secret ... 设置JSON-RPC密钥 (默认: None)
--rpc-open-browser BOOL
RPC服务端启动后自动打开浏览器页面 (默认: True)
--delete-task-files BOOL
删除任务时同时删除下载的文件 (默认: False)
-a BOOL, --archive BOOL
Expand Down
13 changes: 8 additions & 5 deletions README.cht.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/fffonion/xeHentai.svg?branch=dev)](https://travis-ci.org/fffonion/xeHentai)

[English](README.md) [简体中文](README.chs.md)
[English](README.md) [繁體中文](README.cht.md)

[xeHentai Web界面](https://github.com/fffonion/xeHentai-webui)

Expand Down Expand Up @@ -37,6 +37,7 @@ xeH
- **download_ori** 是否下載原圖,默認為否
- **jpn_title** 是否使用日語標題,如果關閉則使用英文或羅馬字標題,默認為是
- **rename_ori** 將圖片重命名為原始名稱,如果關閉則使用序號,默認為否
- **make_archive** 是否下載完成後生成zip壓縮包,並刪除下載目錄,默認為否

高級參數:

Expand All @@ -47,7 +48,6 @@ xeH
- **rpc_port** RPC綁定的埠,默認為`None`
- **rpc_secret** RPC密鑰,默認為`None` (不開啟RPC伺服器)
- **delete_task_files** 是否刪除任務時同時刪除下載的文件,默認為否
- **make_archive** 是否下載完成後生成zip壓縮包,並刪除下載目錄,默認為否
- **download_range** 設置下載的圖片範圍,參見[下載範圍](#下載範圍)
- **scan_thread_cnt** 掃描線程數,默認為`1`
- **download_thread_cnt** 下載線程數,默認為`5`
Expand All @@ -64,9 +64,10 @@ xeH
用法: xeH [-u USERNAME] [-k KEY] [-c COOKIE] [-i] [--daemon] [-d DIR] [-o]
[-j BOOL] [-r BOOL] [-p PROXY] [--proxy-image | --proxy-image-only]
[--rpc-interface ADDR] [--rpc-port PORT] [--rpc-secret ...]
[--delete-task-files BOOL] [-a BOOL] [--download-range a-b,c-d,e]
[-t N] [--timeout N] [--low-speed-threshold N] [-f]
[-l /path/to/eh.log] [-v] [-h] [--version]
[--rpc-open-browser BOOL] [--delete-task-files BOOL] [-a BOOL]
[--download-range a-b,c-d,e] [-t N] [--timeout N]
[--low-speed-threshold N] [-f] [-l /path/to/eh.log] [-v] [-h]
[--version]
[url [url ...]]
紳♂士下載器
Expand Down Expand Up @@ -96,6 +97,8 @@ xeH
--rpc-interface ADDR 設置JSON-RPC監聽IP (默認: localhost)
--rpc-port PORT 設置JSON-RPC監聽埠 (默認: None)
--rpc-secret ... 設置JSON-RPC密鑰 (默認: None)
--rpc-open-browser BOOL
RPC服務端啟動後自動打開瀏覽器頁面 (默認: True)
--delete-task-files BOOL
刪除任務時同時刪除下載的文件 (默認: False)
-a BOOL, --archive BOOL
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ Configuration keys:
- **download_ori** Set to download original images or not. Default to `False`.
- **jpn_title** Set to select Japanese title or not. If set to `False`, English or Romaji title will be used. Default to `True`.
- **rename_ori** Set to rename images to their orginal names. If set to `False`, image will be named in sequence numbers. Default to `False`.
- **make_archive** Set to make a ZIP archive after download and delete downloaded directory. Default to `False`.

- **proxy** Proxy list. Refer to [Proxies](#proxies).
- **proxy_image** Set to use proxy both on downloading images and scanning webpages. Default to `True`.
- **proxy_image_only** Set to use proxy only on downloading images. Default to `False`.
- **rpc_interface** RPC server binding IP. Refer to [JSON-RPC](#json-rpc). Default to `localhost`.
- **rpc_port** RPC server binding port. Default to `none` (not serving).
- **rpc_secret** RPC secret key. Default to `None`.
- **rpc_open_browser** automatically open browser after RPC server starts. Default to `True`.
- **delete_task_files** Set to delete downloaded files when deleting a task. Default to `False`.
- **make_archive** Set to make a ZIP archive after download and delete downloaded directory. Default to `False`.
- **download_range** Set image download range. Refer to [Download range](#download-range). Default to download all images.
- **scan_thread_cnt** Thread count for scanning webpages. Default to `1`.
- **download_thread_cnt** Thread count for downloading images. Default to `5`.
Expand All @@ -62,9 +63,10 @@ Configuration keys:
Usage: xeh [-u USERNAME] [-k KEY] [-c COOKIE] [-i] [--daemon] [-d DIR] [-o]
[-j BOOL] [-r BOOL] [-p PROXY] [--proxy-image | --proxy-image-only]
[--rpc-interface ADDR] [--rpc-port PORT] [--rpc-secret ...]
[--delete-task-files BOOL] [-a BOOL] [--download-range a-b,c-d,e]
[-t N] [--timeout N] [--low-speed-threshold N] [-f]
[-l /path/to/eh.log] [-v] [-h] [--version]
[--rpc-open-browser BOOL] [--delete-task-files BOOL] [-a BOOL]
[--download-range a-b,c-d,e] [-t N] [--timeout N]
[--low-speed-threshold N] [-f] [-l /path/to/eh.log] [-v] [-h]
[--version]
[url [url ...]]
xeHentai Downloader NG
Expand Down Expand Up @@ -103,6 +105,9 @@ optional arguments:
localhost)
--rpc-port PORT bind jsonrpc server to this port (default: 8010)
--rpc-secret ... jsonrpc secret string (default: None)
--rpc-open-browser BOOL
automatically open browser after RPC server starts
(default: True)
--delete-task-files BOOL
delete downloaded files when deleting a task (default:
True)
Expand Down
2 changes: 2 additions & 0 deletions xeHentai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def parse_opt():
help = i18n.XEH_OPT_rpc_port)
parser.add_argument('--rpc-secret', metavar = "...", default = _def['rpc_secret'],
help = i18n.XEH_OPT_rpc_secret)
parser.add_argument('--rpc-open-browser', type = bool, metavar = "BOOL", default = _def['rpc_open_browser'],
help = i18n.XEH_OPT_rpc_open_browser)
parser.add_argument('--delete-task-files', type = bool, metavar = "BOOL", default = _def['delete_task_files'],
dest = 'delete_task_files', help = i18n.XEH_OPT_delete_task_files)
parser.add_argument('-a', '--archive', type = bool, metavar = "BOOL", default = _def['make_archive'],
Expand Down
2 changes: 2 additions & 0 deletions xeHentai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
rpc_port = None
# jsonrpc secret string
rpc_secret = None
# auto open browser on rpc start
rpc_open_browser = True

# make an archive (.zip) after download and delete directory
make_archive = False
Expand Down
4 changes: 4 additions & 0 deletions xeHentai/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

DUMMY_FILENAME = "-dummy-"
RENAME_TMPDIR = "-xeh-conflict-"
STATIC_CACHE_FILE = os.path.join(FILEPATH, "webui.gz")
# cache for 1 hour
STATIC_CACHE_TTL = 3600
STATIC_CACHE_VERSION = 1

RE_INDEX = re.compile('.+/(\d+)/([^\/]+)/*')
RE_GALLERY = re.compile('/([a-f0-9]{10})/[^\-]+\-(\d+)')
Expand Down
1 change: 1 addition & 0 deletions xeHentai/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def update_config(self, **cfg_dict):
if not self.rpc and self.cfg['rpc_port'] and self.cfg['rpc_interface']:
self.rpc = RPCServer(self, (self.cfg['rpc_interface'], int(self.cfg['rpc_port'])),
secret = None if 'rpc_secret' not in self.cfg else self.cfg['rpc_secret'],
open_browser = False if 'rpc_open_browser' not in self.cfg else self.cfg['rpc_open_browser'],
logger = self.logger)
if not RE_LOCAL_ADDR.match(self.cfg['rpc_interface']) and \
not self.cfg['rpc_secret']:
Expand Down
2 changes: 2 additions & 0 deletions xeHentai/i18n/en_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
XEH_OPT_rpc_interface = "bind jsonrpc server to this address (current: %(default)s)"
XEH_OPT_rpc_port = "bind jsonrpc server to this port (current: %(default)s)"
XEH_OPT_rpc_secret = "jsonrpc secret string (current: %(default)s)"
XEH_OPT_rpc_open_browser = "automatically open browser after RPC server starts (current: %(default)s)"
XEH_OPT_a = "make an archive (.zip) after download and delete directory (current: %(default)s)"
XEH_OPT_delete_task_files = "delete downloaded files when deleting a task (current: %(default)s)"
XEH_OPT_j = "use Japanese title, use English/Romaji title if turned off (current: %(default)s)"
Expand Down Expand Up @@ -119,6 +120,7 @@
RPC_STARTED = "RPC server listening on %s:%d"
RPC_TOO_OPEN = "RPC server is listening on public interface (%s) but no rpc_secret defined, which is not safe"
RPC_CANNOT_BIND = "RPC server can't listen on requested address: %s"
RPC_WEBUI_PATH = "WebUI is accessible at %s or https://xehentai.yooooo.us"

SESSION_LOAD_EXCEPTION = "exception occurs when loading saved session: %s"
SESSION_WRITE_EXCEPTION = "exception occurs when writing saved session: %s"
Expand Down
2 changes: 2 additions & 0 deletions xeHentai/i18n/zh_hans.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
XEH_OPT_rpc_interface = "设置JSON-RPC监听IP (当前: %(default)s)"
XEH_OPT_rpc_port = "设置JSON-RPC监听端口 (当前: %(default)s)"
XEH_OPT_rpc_secret = "设置JSON-RPC密钥 (当前: %(default)s)"
XEH_OPT_rpc_open_browser = "RPC服务端启动后自动打开浏览器页面 (当前: %(default)s)"
XEH_OPT_a = "下载完成后生成zip压缩包并删除下载目录 (当前: %(default)s)"
XEH_OPT_delete_task_files = "删除任务时同时删除下载的文件 (current: %(default)s)"
XEH_OPT_j = "使用日语标题, 如果关闭则使用英文或罗马字标题 (当前: %(default)s)"
Expand Down Expand Up @@ -118,6 +119,7 @@
RPC_STARTED = "RPC服务器监听在 %s:%d"
RPC_TOO_OPEN = "RPC服务器监听在公网IP (%s),为了安全起见应该设置rpc_secret"
RPC_CANNOT_BIND = "RPC服务器无法启动:%s"
RPC_WEBUI_PATH = "WebUI 地址为 %s 或者 https://xehentai.yooooo.us"

SESSION_LOAD_EXCEPTION = "读取存档时遇到错误: %s"
SESSION_WRITE_EXCEPTION = "写入存档时遇到错误: %s"
Expand Down
2 changes: 2 additions & 0 deletions xeHentai/i18n/zh_hant.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
XEH_OPT_rpc_interface = "設置JSON-RPC監聽IP (當前: %(default)s)"
XEH_OPT_rpc_port = "設置JSON-RPC監聽埠 (當前: %(default)s)"
XEH_OPT_rpc_secret = "設置JSON-RPC密鑰 (當前: %(default)s)"
XEH_OPT_rpc_open_browser = "RPC服務端啟動後自動打開瀏覽器頁面 (當前: %(default)s)"
XEH_OPT_a = "下載完成後生成zip壓縮包並刪除下載目錄 (當前: %(default)s)"
XEH_OPT_delete_task_files = "刪除任務時同時刪除下載的文件 (current: %(default)s)"
XEH_OPT_j = "使用日語標題, 如果關閉則使用英文或羅馬字標題 (當前: %(default)s)"
Expand Down Expand Up @@ -118,6 +119,7 @@
RPC_STARTED = "RPC伺服器監聽在 %s:%d"
RPC_TOO_OPEN = "RPC伺服器監聽在公網IP (%s),為了安全起見應該設置rpc_secret"
RPC_CANNOT_BIND = "RPC伺服器無法啟動:%s"
RPC_WEBUI_PATH = "WebUI 地址為 %s 或者 https://xehentai.yooooo.us"

SESSION_LOAD_EXCEPTION = "讀取存檔時遇到錯誤: %s"
SESSION_WRITE_EXCEPTION = "寫入存檔時遇到錯誤: %s"
Expand Down
Loading

0 comments on commit a79c4c3

Please sign in to comment.