Permalink
Browse files

2.018 add jpn_title option #29

  • Loading branch information...
fffonion committed Oct 8, 2017
1 parent 7669bd9 commit 6b04e55e55f7038831953c3b86956cbeb83f9b71
Showing with 25 additions and 8 deletions.
  1. +4 −1 xeHentai/cli.py
  2. +1 −0 xeHentai/config.py
  3. +2 −2 xeHentai/const.py
  4. +4 −3 xeHentai/core.py
  5. +2 −1 xeHentai/filters.py
  6. +3 −1 xeHentai/i18n/en_us.py
  7. +2 −0 xeHentai/i18n/zh_hans.py
  8. +7 −0 xeHentai/task.py
View
@@ -139,6 +139,8 @@ def parse_opt():
help = i18n.XEH_OPT_r)
parser.add_argument('-a', '--archive', type = bool, metavar = "BOOL", default = _def['make_archive'],
dest = 'make_archive', help = i18n.XEH_OPT_a)
parser.add_argument('-j', '--jpn-title', type = bool, metavar = "BOOL", default = _def['jpn_title'],
dest = 'jpn_title', help = i18n.XEH_OPT_j)
parser.add_argument('-h','--help', action = 'help', help = i18n.XEH_OPT_h)
parser.add_argument('--version', action = 'version', version = '%s v%.3f' % (SCRIPT_NAME, __version__),
help = i18n.XEH_OPT_version)
@@ -174,5 +176,6 @@ def _readline(x, default = ""):
_dir = _readline(i18n.PS_DOWNLOAD_DIR % __def_dir) or xeH.cfg['dir']
rename_ori = _readline(i18n.PS_RENAME_ORI, 'y' if xeH.cfg['rename_ori'] else 'n') == 'y'
make_archive = _readline(i18n.PS_MAKE_ARCHIVE, 'y' if xeH.cfg['make_archive'] else 'n') == 'y'
jpn_title = _readline(i18n.PS_JPN_TITLE, 'y' if xeH.cfg['jpn_title'] else 'n') == 'y'
return {'urls': url, 'proxy': proxy, 'download_ori': download_ori, 'dir': _dir, 'rename_ori':rename_ori,
'make_archive': make_archive, 'save_tasks': False}
'make_archive': make_archive, 'jpn_title': jpn_title, 'save_tasks': False}
View
@@ -18,3 +18,4 @@
rpc_secret = None
save_tasks = False
make_archive = False
jpn_title = True
View
@@ -16,8 +16,8 @@
CODEPAGE = locale.getdefaultlocale()[1]
ANDROID = 'ANDROID_ARGUMENT' in os.environ
__version__ = 2.017
DEVELOPMENT = False
__version__ = 2.018
DEVELOPMENT = True
SCRIPT_NAME = "xeHentai"
View
@@ -96,7 +96,8 @@ def _get_httpworker(self, tid, task_q, flt, suc, fail, keep_alive):
def add_task(self, url, cfg_dict = {}):
url = url.strip()
cfg = {k:v for k, v in self.cfg.items() if k in (
"dir", "download_ori", "download_thread_cnt", "scan_thread_cnt", "rename_ori", "make_archive")}
"dir", "download_ori", "download_thread_cnt", "scan_thread_cnt",
"rename_ori", "make_archive", "jpn_title")}
cfg.update(cfg_dict)
if cfg['download_ori'] and not self.has_login:
self.logger.warning(i18n.XEH_DOWNLOAD_ORI_NEED_LOGIN)
@@ -196,7 +197,7 @@ def _do_task(self, task_guid):
try:
r = req.request("GET", task.url,
filters.flt_metadata,
lambda x:task.meta.update(x),
lambda x:task.update_meta(x),
lambda x:task.set_fail(x))
except Exception as ex:
self.logger.error(i18n.TASK_ERROR % (task.guid, traceback.format_exc()))
@@ -247,7 +248,7 @@ def _do_task(self, task_guid):
elif task.state == TASK_STATE_SCAN_IMG:
# print here so that see it after we can join former threads
self.logger.info(i18n.TASK_TITLE % (
task_guid, task.meta['gjname'] or task.meta['gnname']))
task_guid, task.meta['title']))
self.logger.info(i18n.TASK_WILL_DOWNLOAD_CNT % (
task_guid, task.meta['total'] - len(task._flist_done),
task.meta['total']))
View
@@ -48,7 +48,8 @@ def flt_metadata(r, suc, fail):
# meta['resampled'] = {}
meta['gjname'] = util.htmlescape(re.findall('="gj">(.*?)</h1>', r.text)[0])
meta['gnname']= util.htmlescape(re.findall('="gn">(.*?)</h1>', r.text)[0])
meta['title'] = meta['gjname'] if meta['gjname'] else meta['gnname']
# don't assign title now, select gj/gn based on cfg['jpn_title']
# meta['title'] = meta['gjname'] if meta['gjname'] else meta['gnname']
meta['total'] = int(re.findall('Length:</td><td class="gdt2">(\d+)\s+page', r.text)[0])
meta['finished'] = 0
meta['tags'] = {}
View
@@ -52,7 +52,8 @@
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_a = "make an archive (.zip) after download and delete directory"
XEH_OPT_a = "make an archive (.zip) after download and delete directory (current: %(default)s)"
XEH_OPT_j = "use Japanese title, use English/Romaji title if turned off (current: %(default)s)"
XEH_OPT_h = "show this help message and exit"
XEH_OPT_version = "show program's version number and exit"
XEH_OPT_IGNORING_I = "ignoring -i option in daemon mode"
@@ -65,6 +66,7 @@
PS_DOWNLOAD_ORI = "Download original (y/n, default:%s)? > "
PS_RENAME_ORI = "Rename to original name (y/n, default:%s)? > "
PS_MAKE_ARCHIVE = "Make archive (y/n, default:%s)? > "
PS_JPN_TITLE = "Use Japanese title (y/n, default:%s)? > "
PS_DOWNLOAD_DIR = "Download to (default: %s)\npress enter or enter new > "
PROXY_CANDIDATE_CNT = "proxy pool has %d candidates"
View
@@ -52,6 +52,7 @@
XEH_OPT_rpc_port = "设置JSON-RPC监听端口 (当前: %(default)s)"
XEH_OPT_rpc_secret = "设置JSON-RPC密钥 (当前: %(default)s)"
XEH_OPT_a = "下载完成后生成zip压缩包并删除下载目录 (当前: %(default)s)"
XEH_OPT_j = "使用日语标题, 如果关闭则使用英文或罗马字标题 (当前: %(default)s)"
XEH_OPT_h = "显示本帮助信息"
XEH_OPT_version = "显示版本信息"
XEH_OPT_IGNORING_I = "后台模式已忽略 -i 参数"
@@ -65,6 +66,7 @@
PS_DOWNLOAD_ORI = "是否下载原图(默认%s) (y/n)? > "
PS_RENAME_ORI = "是否自动重命名(默认%s) (y/n)? > "
PS_MAKE_ARCHIVE = "是否制作zip压缩包(默认%s) (y/n)? > "
PS_JPN_TITLE = "是否使用日语标题(默认%s) (y/n)? > "
PS_DOWNLOAD_DIR = "下载目录 (当前: %s)\n回车确认或输入新路径 > "
PROXY_CANDIDATE_CNT = "代理池中有%d个代理"
View
@@ -68,6 +68,13 @@ def migrate_exhentai(self):
self.failcode = 0
return True
def update_meta(self, meta):
self.meta.update(meta)
if self.config['jpn_title'] and self.meta['gjname']:
self.meta['title'] = self.meta['gjname']
else:
self.meta['title'] = self.meta['gnname']
# def guess_ori(self):
# # guess if this gallery has resampled files depending on some sample hashes
# # return True if it's ori

0 comments on commit 6b04e55

Please sign in to comment.