Skip to content

Commit

Permalink
增加参数跳过有nfo的dir (#446)
Browse files Browse the repository at this point in the history
* 增加参数跳过有nfo的dir

* 补充config_migration

---------

Co-authored-by: LW <[email protected]>
  • Loading branch information
LWWD and LW authored Dec 13, 2024
1 parent 79ab933 commit 227eef1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ scanner:
# 匹配番号时忽略小于指定大小的文件
# 格式要求:https://docs.pydantic.dev/2.0/usage/types/bytesize/
minimum_size: 232MiB

skip_nfo_dir: yes
################################
network:
# 设置代理服务器地址,支持 http, socks5/socks5h 代理,比如'http://127.0.0.1:1080'
Expand Down
1 change: 1 addition & 0 deletions javsp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Scanner(BaseConfig):
filename_extensions: List[str]
ignored_folder_name_pattern: List[str]
minimum_size: ByteSize
skip_nfo_dir: bool

class CrawlerID(str, Enum):
airav = 'airav'
Expand Down
6 changes: 6 additions & 0 deletions javsp/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def scan_movies(root: str) -> List[Movie]:
for name in dirnames.copy():
if ignore_folder_name_pattern.match(name):
dirnames.remove(name)
# 移除有nfo的文件夹
if Cfg().scanner.skip_nfo_dir:
if any(file.lower().endswith(".nfo") for file in os.listdir(os.path.join(dirpath, name)) if isinstance(file, str)):
print(f"skip file {name}")
dirnames.remove(name)

for file in filenames:
ext = os.path.splitext(file)[1].lower()
if ext in Cfg().scanner.filename_extensions:
Expand Down
19 changes: 14 additions & 5 deletions tools/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
exit(1)

cfg = ConfigParser()
cfg.read(args.input)
try:
with open(args.input, 'r', encoding='utf-8') as f:
cfg.read_file(f);
except UnicodeDecodeError:
with open(args.input, 'r', encoding='gbk') as f:
cfg.read_file(f);
except FileNotFoundError:
print(f"Error: The file '{args.input}' was not found.")
sys.exit(1)

ignore_regexes: list[str] = cfg['MovieID']['ignore_regex'].split(';')
ignore_regexes += cfg['MovieID']['ignore_whole_word'].split(';')
Expand All @@ -29,8 +37,9 @@
filename_extensions = cfg['File']['media_ext'].split(';')

ignored_folders = cfg['File']['ignore_folder'].split(';')

proxy_disabled = cfg['Network']['use_proxy'] == 'no' or cfg['Network']['proxy'] == ''
skip_nfo_dir = cfg['File'].get('skip_nfo_dir', 'no')


def yes_to_true(s):
return 'true' if s == 'yes' else 'false'
Expand Down Expand Up @@ -70,6 +79,7 @@ def fix_pat(p):
# 匹配番号时忽略小于指定大小的文件
# 格式要求:https://docs.pydantic.dev/2.0/usage/types/bytesize/
minimum_size: {cfg['File']['ignore_video_file_less_than']}MiB
skip_nfo_dir: {skip_nfo_dir}
################################
network:
Expand Down Expand Up @@ -189,9 +199,9 @@ def fix_pat(p):
extra_fanarts:
# 是否下载剧照?
enabled: {yes_to_true(cfg['Picture']['use_extra_fanarts'])}
enabled: {yes_to_true(cfg['Picture'].get('use_extra_fanarts','no'))}
# 间隔的两次封面爬取请求之间应该间隔多久
scrap_interval: PT{cfg['Picture']['extra_fanarts_scrap_interval']}S
scrap_interval: PT{cfg['Picture'].get('extra_fanarts_scrap_interval','no')}S
################################
translator:
Expand Down Expand Up @@ -246,4 +256,3 @@ def fix_pat(p):

with open(args.output, mode ="w") as file:
file.write(config_str)

0 comments on commit 227eef1

Please sign in to comment.