From c67845f66ad97b1af5c69c34787a29d8023e9bc7 Mon Sep 17 00:00:00 2001 From: Nriver <6752679+Nriver@users.noreply.github.com> Date: Thu, 23 May 2024 16:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E5=A4=9A?= =?UTF-8?q?=E7=BB=84offset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EpisodeReName.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/EpisodeReName.py b/EpisodeReName.py index 379a44b..7ec8e96 100644 --- a/EpisodeReName.py +++ b/EpisodeReName.py @@ -515,8 +515,43 @@ def ep_offset_patch(file_path, ep): if offset_str: try: offset_str = offset_str.strip().replace(' ', '') - # 直接取整数, 正数为减少, 负数是增加 - offset = int(offset_str) + if '|' not in offset_str: + logger.info('单一数字类型的offset') + # 直接取整数, 正数为减少, 负数是增加 + offset = int(offset_str) + else: + logger.info('多组数据的offset解析') + # 和 QRM 多组匹配对应的多组offset + # 比如: 格式 `12|0|-11` 第一组集数减12, 第二组不变, 第三组加11 + + if not qrm_config: + logger.info('未获取到QRM的配置,默认取第一个offset') + offset = int(offset_str.sptit('|')[0].strip()) + else: + # 查找QRM配置匹配的组序号 + index = 0 + for data_group in qrm_config['data_dump']['data_groups']: + for x in data_group['data']: + if format_path(x['savePath']) == format_path(season_path): + try: + must_contain_tmp = x['mustContain'] + if '|' not in must_contain_tmp: + break + else: + for i, keywords in enumerate(must_contain_tmp.split('|')): + if all( + [ + keyword.strip() in file_path + for keyword in keywords.strip().split(' ') + ] + ): + index = i + break + except: + pass + # 获取offset + offset = int(offset_str.split('|')[index].strip()) + logger.info(f'解析offset {offset}') if '.' in ep: ep_int, ep_tail = ep.split('.')