@@ -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 """
0 commit comments