Skip to content

Commit bb93919

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 3acb2b2 + ff900c5 commit bb93919

3 files changed

Lines changed: 65 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ docker pull jxxghp/moviepilot:latest
7878
- **COOKIECLOUD_PASSWORD:** CookieCloud端对端加密密码
7979
- **COOKIECLOUD_INTERVAL:** CookieCloud同步间隔(分钟)
8080
- **USER_AGENT:** CookieCloud对应的浏览器UA,可选,设置后可增加连接站点的成功率,同步站点后可以在管理界面中修改
81+
- **AUTO_DOWNLOAD_USER:** 交互搜索自动下载用户ID,使用,分割
8182
- **MESSAGER:** 消息通知渠道,支持 `telegram`/`wechat`/`slack`,开启多个渠道时使用`,`分隔。同时还需要配置对应渠道的环境变量,非对应渠道的变量可删除,推荐使用`telegram`
8283

8384
- `wechat`设置项:

app/chain/message.py

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,29 @@ def process(self, body: Any, form: Any, args: Any) -> None:
130130
return
131131
# 搜索结果排序
132132
contexts = self.torrenthelper.sort_torrents(contexts)
133-
# 更新缓存
134-
user_cache[userid] = {
135-
"type": "Torrent",
136-
"items": contexts
137-
}
138-
# 发送种子数据
139-
logger.info(f"搜索到 {len(contexts)} 条数据,开始发送选择消息 ...")
140-
self.__post_torrents_message(channel=channel,
141-
title=mediainfo.title,
142-
items=contexts[:self._page_size],
143-
userid=userid,
144-
total=len(contexts))
133+
# 判断是否设置自动下载
134+
auto_download_user = settings.AUTO_DOWNLOAD_USER
135+
# 匹配到自动下载用户
136+
if auto_download_user and any(userid == user for user in auto_download_user.split(",")):
137+
logger.info(f"用户 {userid} 在自动下载用户中,开始自动择优下载")
138+
# 自动选择下载
139+
self.__auto_download(channel=channel,
140+
cache_list=contexts,
141+
userid=userid,
142+
username=username)
143+
else:
144+
# 更新缓存
145+
user_cache[userid] = {
146+
"type": "Torrent",
147+
"items": contexts
148+
}
149+
# 发送种子数据
150+
logger.info(f"搜索到 {len(contexts)} 条数据,开始发送选择消息 ...")
151+
self.__post_torrents_message(channel=channel,
152+
title=mediainfo.title,
153+
items=contexts[:self._page_size],
154+
userid=userid,
155+
total=len(contexts))
145156

146157
elif cache_type == "Subscribe":
147158
# 订阅媒体
@@ -168,36 +179,10 @@ def process(self, body: Any, form: Any, args: Any) -> None:
168179
elif cache_type == "Torrent":
169180
if int(text) == 0:
170181
# 自动选择下载
171-
# 查询缺失的媒体信息
172-
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=_current_meta,
173-
mediainfo=_current_media)
174-
if exist_flag:
175-
self.post_message(Notification(
176-
channel=channel,
177-
title=f"{_current_media.title_year}"
178-
f"{_current_meta.sea} 媒体库中已存在",
179-
userid=userid))
180-
return
181-
# 批量下载
182-
downloads, lefts = self.downloadchain.batch_download(contexts=cache_list,
183-
no_exists=no_exists,
184-
userid=userid)
185-
if downloads and not lefts:
186-
# 全部下载完成
187-
logger.info(f'{_current_media.title_year} 下载完成')
188-
else:
189-
# 未完成下载
190-
logger.info(f'{_current_media.title_year} 未下载未完整,添加订阅 ...')
191-
# 添加订阅,状态为R
192-
self.subscribechain.add(title=_current_media.title,
193-
year=_current_media.year,
194-
mtype=_current_media.type,
195-
tmdbid=_current_media.tmdb_id,
196-
season=_current_meta.begin_season,
197-
channel=channel,
198-
userid=userid,
199-
username=username,
200-
state="R")
182+
self.__auto_download(channel=channel,
183+
cache_list=cache_list,
184+
userid=userid,
185+
username=username)
201186
else:
202187
# 下载种子
203188
context: Context = cache_list[int(text) - 1]
@@ -336,6 +321,41 @@ def process(self, body: Any, form: Any, args: Any) -> None:
336321
# 保存缓存
337322
self.save_cache(user_cache, self._cache_file)
338323

324+
def __auto_download(self, channel, cache_list, userid, username):
325+
"""
326+
自动择优下载
327+
"""
328+
# 查询缺失的媒体信息
329+
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=_current_meta,
330+
mediainfo=_current_media)
331+
if exist_flag:
332+
self.post_message(Notification(
333+
channel=channel,
334+
title=f"{_current_media.title_year}"
335+
f"{_current_meta.sea} 媒体库中已存在",
336+
userid=userid))
337+
return
338+
# 批量下载
339+
downloads, lefts = self.downloadchain.batch_download(contexts=cache_list,
340+
no_exists=no_exists,
341+
userid=userid)
342+
if downloads and not lefts:
343+
# 全部下载完成
344+
logger.info(f'{_current_media.title_year} 下载完成')
345+
else:
346+
# 未完成下载
347+
logger.info(f'{_current_media.title_year} 未下载未完整,添加订阅 ...')
348+
# 添加订阅,状态为R
349+
self.subscribechain.add(title=_current_media.title,
350+
year=_current_media.year,
351+
mtype=_current_media.type,
352+
tmdbid=_current_media.tmdb_id,
353+
season=_current_meta.begin_season,
354+
channel=channel,
355+
userid=userid,
356+
username=username,
357+
state="R")
358+
339359
def __post_medias_message(self, channel: MessageChannel,
340360
title: str, items: list, userid: str, total: int):
341361
"""

app/core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class Settings(BaseSettings):
6565
INDEXER: str = "builtin"
6666
# 用户认证站点 hhclub/audiences/hddolby/zmpt/freefarm/hdfans/wintersakura/leaves/1ptba/icc2022/iyuu
6767
AUTH_SITE: str = ""
68+
# 交互搜索自动下载用户ID,使用,分割
69+
AUTO_DOWNLOAD_USER: str = None
6870
# 消息通知渠道 telegram/wechat/slack
6971
MESSAGER: str = "telegram"
7072
# WeChat企业ID

0 commit comments

Comments
 (0)