@@ -200,7 +200,10 @@ def check_task_rss(self, taskid):
200
200
log .info ("【Brush】开始站点 %s 的刷流任务:%s..." % (site_name , task_name ))
201
201
# 检查是否达到保种体积
202
202
if not self .__is_allow_new_torrent (taskinfo = taskinfo ,
203
- dlcount = rss_rule .get ("dlcount" )):
203
+ dlcount = rss_rule .get ("dlcount" ),
204
+ current_site_count = rss_rule .get ("current_site_count" ),
205
+ current_site_dlcount = rss_rule .get ("current_site_dlcount" ),
206
+ site_info = site_info ):
204
207
return
205
208
206
209
rss_result = self .rsshelper .parse_rssxml (url = rss_url , proxy = site_proxy )
@@ -222,6 +225,11 @@ def check_task_rss(self, taskid):
222
225
downloading_count = self .__get_downloading_count (downloader_id ) or 0
223
226
new_torrent_count = int (max_dlcount ) - int (downloading_count )
224
227
228
+ # 当前站点任务总数
229
+ current_site_count = rss_rule .get ("current_site_count" )
230
+ # 当前站点下载任务数
231
+ current_site_dlcount = rss_rule .get ("current_site_dlcount" )
232
+
225
233
for res in rss_result :
226
234
try :
227
235
# 种子名
@@ -253,7 +261,10 @@ def check_task_rss(self, taskid):
253
261
# 检查能否添加当前种子,判断是否超过保种体积大小
254
262
if not self .__is_allow_new_torrent (taskinfo = taskinfo ,
255
263
dlcount = max_dlcount ,
256
- torrent_size = size ):
264
+ torrent_size = size ,
265
+ current_site_count = current_site_count ,
266
+ current_site_dlcount = current_site_dlcount ,
267
+ site_info = site_info ):
257
268
continue
258
269
# 检查是否已处理过
259
270
if self .is_torrent_handled (enclosure = enclosure ):
@@ -275,7 +286,10 @@ def check_task_rss(self, taskid):
275
286
276
287
# 再判断一次
277
288
if not self .__is_allow_new_torrent (taskinfo = taskinfo ,
278
- dlcount = max_dlcount ):
289
+ dlcount = max_dlcount ,
290
+ current_site_count = current_site_count ,
291
+ current_site_dlcount = current_site_dlcount ,
292
+ site_info = site_info ):
279
293
break
280
294
self ._torrents_cache .append (enclosure )
281
295
except Exception as err :
@@ -529,7 +543,7 @@ def __send_message(_task_name, _delete_type, _torrent_name, _download_name, _tor
529
543
except Exception as e :
530
544
ExceptionUtils .exception_traceback (e )
531
545
532
- def __is_allow_new_torrent (self , taskinfo , dlcount , torrent_size = None ):
546
+ def __is_allow_new_torrent (self , taskinfo , dlcount , current_site_dlcount , current_site_count , site_info , torrent_size = None ):
533
547
"""
534
548
检查是否还能添加新的下载
535
549
"""
@@ -570,21 +584,59 @@ def __is_allow_new_torrent(self, taskinfo, dlcount, torrent_size=None):
570
584
571
585
# 检查正在下载的任务数
572
586
if dlcount :
573
- downloading_count = self .__get_downloading_count (downloader_id )
574
- if downloading_count is None :
587
+ downloading_total_count = self .__get_downloading_count (downloader_id )
588
+ if downloading_total_count is None :
575
589
log .error ("【Brush】任务 %s 下载器 %s 无法连接" % (task_name , downloader_name ))
576
590
return False
577
- if int (downloading_count ) >= int (dlcount ):
591
+ if int (downloading_total_count ) >= int (dlcount ):
578
592
log .warn ("【Brush】下载器 %s 正在下载任务数:%s,超过设定上限,暂不添加下载" % (
579
- downloader_name , downloading_count ))
593
+ downloader_name , downloading_total_count ))
594
+ return False
595
+
596
+ # 检查是否添加标签
597
+ label = list (set ((taskinfo .get ("label" ).split (',' ) if taskinfo .get ("label" ) else []) +
598
+ (site_info .get ("tags" ).split (',' ) if site_info .get ("tags" ) else [])))
599
+ if label is None or len (label ) <= 0 :
600
+ return True
601
+
602
+ site_name = site_info .get ("name" )
603
+
604
+ # 检查当前站点正在下载的任务数量
605
+ if current_site_dlcount :
606
+ current_site_count_downloading = self .__get_downloading_count (downloader_id , tag = label )
607
+ if current_site_count_downloading is None :
608
+ log .error ("【Brush】任务 %s 下载器 %s 无法连接" % (task_name , downloader_name ))
609
+ return False
610
+ if int (current_site_count_downloading ) >= int (current_site_count ):
611
+ log .warn ("【Brush】站点 %s 正在下载任务数:%s,超过设定上限,暂不添加下载" % (
612
+ site_name , current_site_count_downloading ))
580
613
return False
614
+
615
+ # 检查当前站点任务数量
616
+ if current_site_count :
617
+ current_site_count_total = self .__get_task_count (downloader_id , tag = label )
618
+ if current_site_count_total is None :
619
+ log .error ("【Brush】任务 %s 下载器 %s 无法连接" % (task_name , downloader_name ))
620
+ return False
621
+ if int (current_site_count_total ) >= int (current_site_count ):
622
+ log .warn ("【Brush】站点 %s 任务总数:%s,超过设定上限,暂不添加下载" % (
623
+ site_name , current_site_count_total ))
624
+ return False
625
+
581
626
return True
582
627
583
- def __get_downloading_count (self , downloader_id ):
628
+ def __get_downloading_count (self , downloader_id , tag = None ):
629
+ """
630
+ 查询当前正在下载的任务数,支持限定 tag
631
+ """
632
+ torrents = self .downloader .get_downloading_torrents (downloader_id = downloader_id , tag = tag ) or []
633
+ return len (torrents )
634
+
635
+ def __get_task_count (self , downloader_id , tag ):
584
636
"""
585
- 查询当前正在下载的任务数
637
+ 查询当前任务总数,限定 tag
586
638
"""
587
- torrents = self .downloader .get_downloading_torrents (downloader_id = downloader_id ) or []
639
+ torrents = self .downloader .get_torrents (downloader_id = downloader_id , tag = tag ) or []
588
640
return len (torrents )
589
641
590
642
def __download_torrent (self ,
0 commit comments