Skip to content

Commit abf0aa7

Browse files
committed
release: v0.1.1 add WEBHOOK_OPENLIST_NAME and remove legacy refresh fallbacks
1 parent 9899fd1 commit abf0aa7

5 files changed

Lines changed: 35 additions & 32 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ services:
179179
user: "1000:1001"
180180
environment:
181181
- WEBHOOK_DELAY=60 # Webhook延迟触发秒数 取决是否需要等MoviePilot刮削完成后同步,如果不需要可以设置为3
182+
# - WEBHOOK_OPENLIST_NAME=OpenList # Webhook 自动创建任务时使用的 OpenList 引擎备注名;若未配置或留空,默认使用第一个引擎
182183
- TVsource=/media/电视剧 # 电视剧源根目录
183184
- MOVsource=/media/电影 # 电影源根目录
184185
# DST开头变量适用于临时存放(如追新电视剧),整季完结后可删除并同步至SYNC路径,非必要不需要启用!
@@ -260,6 +261,8 @@ task_timeout=72
260261

261262
| 变量 | 说明 | 示例 |
262263
|---|---|---|
264+
| `WEBHOOK_DELAY` | Webhook 延迟触发时间(秒) | `60` |
265+
| `WEBHOOK_OPENLIST_NAME` | Webhook 自动创建任务时使用的 OpenList 引擎备注名;若未配置或留空,默认使用第一个引擎 | `OpenList` |
263266
| `TVsource` | 电视剧源根 | `/media/电视剧` |
264267
| `MOVsource` | 电影源根 | `/media/电影` |
265268
| `DST_TV_TARGETS` / `DST_MOV_TARGETS` | 优先同步根集合(原样使用),存在同名目录时仅同步到这里;仅在末尾追加“名称(年份)”;支持 `,;:` 分隔 | 例如 `/shanct/电视剧` 或 `/shanct/电影` |

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
user: "1000:1001"
1111
environment:
1212
- WEBHOOK_DELAY=60 # Webhook延迟触发秒数 取决是否需要等MoviePilot刮削完成后同步,如果不需要可以设置为3
13+
# - WEBHOOK_OPENLIST_NAME=OpenList # Webhook 自动创建任务时使用的 OpenList 引擎备注名;若未配置或留空,默认使用第一个引擎
1314
- TVsource=/media/电视剧 # 电视剧源根目录
1415
- MOVsource=/media/电影 # 电影源根目录
1516
# DST开头变量适用于临时存放(如追新),整季完结后可删除并同步至SYNC路径

service/webhook/refreshService.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,6 @@ def _expand_targets(env_s, client):
8080
return arr
8181
raw = [p.strip() for p in re.split(r"[,;:]", env_s) if p and p.strip() != '']
8282

83-
# 获取 /ODC 下的默认 tv/mov 前缀,仅用于兼容 {odc_tv}/{odc_mov} 占位符
84-
# 如果用户不使用这俩旧占位符,这里的查询其实是多余的,但为了保持对旧配置的兼容,还是保留比较稳妥
85-
# 既然用户明确要求"不用兼容旧的"(可能是指不需要默认去搜根目录下的 tv/mov),
86-
# 那么我们可以把这里写死的 '/' 改成 '/ODC' 或者干脆去掉这两个变量?
87-
# 但下方代码还用到了 tv_prefix_default 和 mov_prefix_default 来替换 {odc_tv}/{odc_mov}
88-
# 如果完全移除,旧占位符将失效。
89-
# 用户意图应该是:不要写死搜索根目录 '/'。
90-
# 之前的逻辑是搜索 '/ODC',后来为了去硬编码改成了 '/'。
91-
# 如果用户彻底不用 {odc_tv},那这两行确实没用。
92-
# 但为了代码健壮性(防止配置文件里还有旧占位符导致崩溃),建议保留变量定义,但可以设为空字符串或者不进行搜索?
93-
# 或者,我们遵循用户的"写死的路径都删掉",既然 {odc_tv} 本身就隐含了 ODC,
94-
# 那么这里应该恢复成搜索 /ODC 吗?不,用户之前说要删掉 /ODC。
95-
# 最彻底的做法:如果用户不再使用 {odc_tv},那这两行和下面的 replace 都可以删掉。
96-
# 但如果用户只是说"这里代码还有写死的",是指 `_find_max_dir(client, '/', 'tv')` 里的 `'/'` 吗?
97-
98-
# 让我们假设用户希望彻底移除对 {odc_tv} 的隐式支持逻辑,完全依赖 {max}。
99-
# 那么我们可以移除这两个默认搜索。
100-
10183
for base in raw:
10284
# 1. 处理通用 {max} 语法
10385
def max_replacer(match):
@@ -147,7 +129,6 @@ def refresh_after_task(job, status):
147129
mov_src_norm = re.sub(r"/{2,}", "/", mov_src_env).rstrip('/') + '/' if mov_src_env else ''
148130
is_tv = bool(tv_src_norm and src_norm.startswith(tv_src_norm))
149131
logger.info(f"Refresh context: is_tv={is_tv}, src={src}, dsts={dsts}")
150-
odc_prefix = None
151132
base_paths = []
152133
name = remark
153134
dedup = []
@@ -171,11 +152,10 @@ def refresh_after_task(job, status):
171152
if dst_used:
172153
env_refresh = os.getenv('DST_REFRESH_TV') if is_tv else os.getenv('DST_REFRESH_MOV')
173154
else:
174-
# 尝试获取 SYNC_REFRESH_TV/MOV,如果为空则尝试获取 REFRESH_TV/MOV_TARGETS(兼容旧配置或用户习惯)
175155
if is_tv:
176-
env_refresh = os.getenv('SYNC_REFRESH_TV') or os.getenv('REFRESH_TV_TARGETS')
156+
env_refresh = os.getenv('SYNC_REFRESH_TV')
177157
else:
178-
env_refresh = os.getenv('SYNC_REFRESH_MOV') or os.getenv('REFRESH_MOV_TARGETS')
158+
env_refresh = os.getenv('SYNC_REFRESH_MOV')
179159

180160
logger.info(f"Refresh env config: dst_used={dst_used}, env_refresh={env_refresh}")
181161

service/webhook/webhookService.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,33 @@ def _trigger():
9494
except Exception:
9595
pass
9696
return
97-
openlistId = int(openlists[0]['id'])
97+
98+
openlistId = None
99+
webhook_engine_name = os.getenv('WEBHOOK_OPENLIST_NAME')
100+
101+
if webhook_engine_name:
102+
webhook_engine_name = webhook_engine_name.strip()
103+
target_op = next((op for op in openlists if op.get('remark') == webhook_engine_name), None)
104+
if target_op:
105+
openlistId = int(target_op['id'])
106+
else:
107+
# 如果指定了引擎但未找到,发送通知并停止
108+
try:
109+
lg.error(f"Webhook configured engine '{webhook_engine_name}' not found")
110+
notify_list = notifyService.getNotifyList(True)
111+
if notify_list:
112+
for n in notify_list:
113+
try:
114+
notifyService.sendNotify(n, 'Webhook 错误', f"未找到名称为 '{webhook_engine_name}' 的OpenList引擎", False)
115+
except Exception:
116+
pass
117+
except Exception:
118+
pass
119+
return
120+
else:
121+
# 默认使用第一个引擎
122+
openlistId = int(openlists[0]['id'])
123+
98124
from service.openlist import openlistService
99125
client = None
100126
try:
@@ -189,19 +215,15 @@ def max_replacer(match):
189215

190216
return re.sub(r"(^|.*?/)([^/]*)\{max\}", max_replacer, path_str)
191217

192-
odc_prefix = _pick('tv' if tv_flag else 'mov')
193218
srcPath = f"{media_root.rstrip('/')}/{remark}/"
194219
dst_env = os.getenv('DST_TV_TARGETS') if tv_flag else os.getenv('DST_MOV_TARGETS')
195220
dsts = []
196221
if dst_env and client is not None:
197222
try:
198223
raw_dst = [p.strip() for p in re.split(r"[,;:]", dst_env) if p and p.strip() != '']
199-
tv_prefix = _pick('tv')
200-
mov_prefix = _pick('mov')
201224
for base in raw_dst:
202225
# 支持 {max} 语法
203226
base = _resolve_max_placeholder(base)
204-
base = base.replace('{odc_tv}', tv_prefix).replace('{odc_mov}', mov_prefix)
205227
if not base.startswith('/'):
206228
base = '/' + base
207229
base = re.sub(r"/{2,}", "/", base).rstrip('/')
@@ -216,12 +238,9 @@ def max_replacer(match):
216238
sync_env = os.getenv('SYNC_TV_TARGETS') if tv_flag else os.getenv('SYNC_MOV_TARGETS')
217239
if sync_env:
218240
raw = [p.strip() for p in re.split(r"[,;:]", sync_env) if p and p.strip() != '']
219-
tv_prefix = _pick('tv')
220-
mov_prefix = _pick('mov')
221241
for base in raw:
222242
# 支持 {max} 语法
223243
base = _resolve_max_placeholder(base)
224-
base = base.replace('{odc_tv}', tv_prefix).replace('{odc_mov}', mov_prefix)
225244
if not base.startswith('/'):
226245
base = '/' + base
227246
base = re.sub(r"/{2,}", "/", base).rstrip('/')

version.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
v0.1.0,latest
1+
v0.1.1,latest
22

33

44
该文件仅第一行有效,表示打包的版本。
55
如果要打包多个,以英文,分隔,例如【v1.0.0,latest】;
6-
打包多个仅用于docker镜像,其他情况只认第一个【v1.0.0】。
6+
打包多个仅用于docker镜像,其他情况只认第一个【v1.0.0】。

0 commit comments

Comments
 (0)