Skip to content

Commit

Permalink
add support for interactive/non-interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
glyh committed Sep 28, 2024
1 parent a7c0a32 commit 9832462
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 添加新的爬虫`arzon`, `arzon_iv` [#377](https://github.com/Yuukiy/JavSP/pull/377)
- Slimeface人脸识别 [#380](https://github.com/Yuukiy/JavSP/pull/380)
- 支持Linux和MacOS(x64)二进制 [a754e1c](https://github.com/Yuukiy/JavSP/commit/a754e1ce0f14b0ca9dcc6d43d8e7d322a3da1c43)
- 添加选项`other.interactive`来表示程序是否应该在interactive模式下运行

### Changed
- 使用 Poetry 作为构建系统 [134b279](https://github.com/Yuukiy/JavSP/commit/134b279151aead587db0b12d1a30781f2e1be5b1)
Expand Down
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ translator:

################################
other:
# 是否在stdin/stdout进行交互
interactive: true
# 是否允许检查更新。如果允许,在有新版本时会显示提示信息和新版功能
check_update: true
# 是否允许检查到新版本时自动下载
Expand Down
3 changes: 2 additions & 1 deletion javsp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from javsp.web.translate import translate_movie_info

from javsp.config import Cfg, CrawlerID
from javsp.prompt import prompt

actressAliasMap = {}

Expand Down Expand Up @@ -353,7 +354,7 @@ def reviewMovieID(all_movies, root):
print(f'[{i}/{count}]\t{Fore.LIGHTMAGENTA_EX}{id}{Style.RESET_ALL}, 对应文件:')
relpaths = [os.path.relpath(i, root) for i in movie.files]
print('\n'.join([' '+i for i in relpaths]))
s = input("回车确认当前番号,或直接输入更正后的番号(如'ABC-123'或'cid:sqte00300')")
s = prompt("回车确认当前番号,或直接输入更正后的番号(如'ABC-123'或'cid:sqte00300')", "更正后的番号")
if not s:
logger.info(f"已确认影片番号: {','.join(relpaths)}: {id}")
else:
Expand Down
1 change: 1 addition & 0 deletions javsp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class Translator(BaseConfig):
fields: TranslateField

class Other(BaseConfig):
interactive: bool
check_update: bool
auto_update: bool

Expand Down
3 changes: 2 additions & 1 deletion javsp/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from javsp.web.base import *
from javsp.lib import re_escape, resource_path

from javsp.prompt import prompt

__all__ = ['select_folder', 'get_scan_dir', 'remove_trail_actor_in_title',
'shutdown', 'CLEAR_LINE', 'check_update', 'split_by_punc']
Expand Down Expand Up @@ -61,7 +62,7 @@ def get_scan_dir(cfg_scan_dir: Path | None) -> str | None:
print('请选择要整理的文件夹:', end='')
root = select_folder()
else:
root = input('请选择要整理的文件夹路径,必须是绝对路径: ')
root = prompt('请选择要整理的文件夹路径,必须是绝对路径: ', "要整理的文件夹")
print(root)
return root

Expand Down
7 changes: 7 additions & 0 deletions javsp/prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from javsp.config import Cfg
def prompt(message: str, what: str) -> str:
if Cfg().other.interactive:
return input(message)
else:
print(f"缺少{what}")
exit(1)
2 changes: 2 additions & 0 deletions tools/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ def fix_pat(p):
################################
other:
# 是否在stdin/stdout进行交互
interactive: true
# 是否允许检查更新。如果允许,在有新版本时会显示提示信息和新版功能
check_update: {yes_to_true(cfg['Other']['check_update'])}
# 是否允许检查到新版本时自动下载
Expand Down

0 comments on commit 9832462

Please sign in to comment.