Skip to content

Commit

Permalink
2.014 support add multiple tasks at once
Browse files Browse the repository at this point in the history
fix rename bug
  • Loading branch information
fffonion committed Sep 2, 2016
1 parent 534f161 commit 7ddda78
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 2.0.14
- 修复cookie中只有nw判断为已登录的bug
- 登录失败时显示网页上的错误信息
- 交互支持逗号分割多个任务,命令行模式支持同时添加多个任务
- 修复重命名的bug

## 2.013
- 修复页数>=1000页时抽风的bug
Expand Down
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ Firefox用户需要安装[Greasemonkey](https://addons.mozilla.org/en-US/firefox

### 运行模式

如果通过命令行或交互模式指定了下载url,xeHentai会会在下载完成后退出
如果通过命令行或交互模式指定了下载url,xeHentai会在下载完成`h.json`中存储的任务(如果存在)及指定的url后退出

如果命令行没有指定url,xeHentai将会在完成存档中的队列(如果存在)后继续等待。(待修改)
如果命令行没有指定url,xeHentai将会在完成存档`h.json`中的队列(如果存在)后继续等待。

如果指定了后台模式(`-d`或设置`daemon``True`),xeHentai将会在保持后台运行。

Expand Down
8 changes: 5 additions & 3 deletions xeHentai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ def main(xeH, opt):
if opt.urls:
for u in opt.urls:
xeH.add_task(u.strip())
# finished this task and exit xeHentai
Thread(target = lambda:(time.sleep(0.618), setattr(xeH, "_exit", XEH_STATE_SOFT_EXIT))).start()
# Thread(target = lambda:(time.sleep(0.618), setattr(xeH, "_exit", XEH_STATE_SOFT_EXIT))).start()
Thread(target = xeH._task_loop, name = "main" ).start()
while xeH._exit < XEH_STATE_CLEAN:
# if specify urls, finished this task and exit xeHentai
if opt.urls and not [k for k, v in xeH._all_tasks.items() if TASK_STATE_WAITING <= v.state < TASK_STATE_FINISHED]:
xeH._exit = XEH_STATE_SOFT_EXIT
time.sleep(1)
except KeyboardInterrupt:
log.info(i18n.XEH_CLEANUP)
Expand Down Expand Up @@ -134,7 +136,7 @@ def parse_opt():
parser.add_argument('-r', '--rename-ori', type = bool, metavar = "BOOL", default = _def['rename_ori'],
help = i18n.XEH_OPT_r)
parser.add_argument('-a', '--archive', type = bool, metavar = "BOOL", default = _def['make_archive'],
help = i18n.XEH_OPT_a)
dest = 'make_archive', help = i18n.XEH_OPT_a)
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)
Expand Down
22 changes: 11 additions & 11 deletions xeHentai/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,18 @@ def rename_fname(self):
# thus can't determine if this id is downloaded, because file type is not
# necessarily .jpg
fname_to = os.path.join(fpath, self.get_fidpad(fid, os.path.splitext(fname)[1]))
if os.path.exists(fname_ori):
while os.path.exists(fname_to):
_base, _ext = os.path.splitext(fname_to)
_ = re.findall("\((\d+)\)$", _base)
if _ :# if ...(1) exists, use ...(2)
_base = re.sub("\((\d+)\)$", _base, lambda x:"(%d)" % (int(x.group(1)) + 1))
else:
_base = "%s(1)" % _base
fname_to = "".join((_base, _ext))

if fname_ori != fname_to:
if os.path.exists(fname_ori):
while os.path.exists(fname_to):
_base, _ext = os.path.splitext(fname_to)
_ = re.findall("\((\d+)\)$", _base)
if _ :# if ...(1) exists, use ...(2)
_base = re.sub("\((\d+)\)$", _base, lambda x:"(%d)" % (int(x.group(1)) + 1))
else:
_base = "%s(1)" % _base
fname_to = "".join((_base, _ext))
os.rename(fname_ori, fname_to)
cnt += 1
cnt += 1
if cnt == self.meta['total']:
with open(os.path.join(fpath, ".xehdone"), "w"):
pass
Expand Down

0 comments on commit 7ddda78

Please sign in to comment.