Skip to content

Commit c67845f

Browse files
committed
支持设置多组offset
1 parent 9f0afe7 commit c67845f

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

EpisodeReName.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,43 @@ def ep_offset_patch(file_path, ep):
515515
if offset_str:
516516
try:
517517
offset_str = offset_str.strip().replace(' ', '')
518-
# 直接取整数, 正数为减少, 负数是增加
519-
offset = int(offset_str)
518+
if '|' not in offset_str:
519+
logger.info('单一数字类型的offset')
520+
# 直接取整数, 正数为减少, 负数是增加
521+
offset = int(offset_str)
522+
else:
523+
logger.info('多组数据的offset解析')
524+
# 和 QRM 多组匹配对应的多组offset
525+
# 比如: 格式 `12|0|-11` 第一组集数减12, 第二组不变, 第三组加11
526+
527+
if not qrm_config:
528+
logger.info('未获取到QRM的配置,默认取第一个offset')
529+
offset = int(offset_str.sptit('|')[0].strip())
530+
else:
531+
# 查找QRM配置匹配的组序号
532+
index = 0
533+
for data_group in qrm_config['data_dump']['data_groups']:
534+
for x in data_group['data']:
535+
if format_path(x['savePath']) == format_path(season_path):
536+
try:
537+
must_contain_tmp = x['mustContain']
538+
if '|' not in must_contain_tmp:
539+
break
540+
else:
541+
for i, keywords in enumerate(must_contain_tmp.split('|')):
542+
if all(
543+
[
544+
keyword.strip() in file_path
545+
for keyword in keywords.strip().split(' ')
546+
]
547+
):
548+
index = i
549+
break
550+
except:
551+
pass
552+
# 获取offset
553+
offset = int(offset_str.split('|')[index].strip())
554+
logger.info(f'解析offset {offset}')
520555

521556
if '.' in ep:
522557
ep_int, ep_tail = ep.split('.')

0 commit comments

Comments
 (0)