This commit is contained in:
jxxghp
2025-06-27 07:53:10 +08:00
parent 8068523d88
commit 4dd5ea8e2f
8 changed files with 220 additions and 188 deletions
+2
View File
@@ -264,7 +264,9 @@ class SearchChain(ChainBase):
meta_info=t[1]) for t in _match_torrents] meta_info=t[1]) for t in _match_torrents]
finally: finally:
torrents.clear() torrents.clear()
del torrents
_match_torrents.clear() _match_torrents.clear()
del _match_torrents
# 排序 # 排序
progress.update(value=99, progress.update(value=99,
+17 -4
View File
@@ -364,6 +364,7 @@ class SubscribeChain(ChainBase):
# 过滤搜索结果 # 过滤搜索结果
matched_contexts = [] matched_contexts = []
try:
for context in contexts: for context in contexts:
if global_vars.is_system_stopped: if global_vars.is_system_stopped:
break break
@@ -390,6 +391,9 @@ class SubscribeChain(ChainBase):
if subscribe.episode_group: if subscribe.episode_group:
torrent_mediainfo.episode_group = subscribe.episode_group torrent_mediainfo.episode_group = subscribe.episode_group
matched_contexts.append(context) matched_contexts.append(context)
finally:
contexts.clear()
del contexts
if not matched_contexts: if not matched_contexts:
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源') logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
@@ -432,6 +436,7 @@ class SubscribeChain(ChainBase):
logger.debug(f"search Lock released at {datetime.now()}") logger.debug(f"search Lock released at {datetime.now()}")
finally: finally:
subscribes.clear() subscribes.clear()
del subscribes
def update_subscribe_priority(self, subscribe: Subscribe, meta: MetaBase, def update_subscribe_priority(self, subscribe: Subscribe, meta: MetaBase,
mediainfo: MediaInfo, downloads: Optional[List[Context]]): mediainfo: MediaInfo, downloads: Optional[List[Context]]):
@@ -552,7 +557,6 @@ class SubscribeChain(ChainBase):
return return
with self._rlock: with self._rlock:
try:
logger.debug(f"match lock acquired at {datetime.now()}") logger.debug(f"match lock acquired at {datetime.now()}")
# 预识别所有未识别的种子 # 预识别所有未识别的种子
@@ -578,6 +582,7 @@ class SubscribeChain(ChainBase):
# 所有订阅 # 所有订阅
subscribes = SubscribeOper().list(self.get_states_for_search('R')) subscribes = SubscribeOper().list(self.get_states_for_search('R'))
try:
for subscribe in subscribes: for subscribe in subscribes:
if global_vars.is_system_stopped: if global_vars.is_system_stopped:
break break
@@ -628,12 +633,14 @@ class SubscribeChain(ChainBase):
torrenthelper = TorrentHelper() torrenthelper = TorrentHelper()
systemconfig = SystemConfigOper() systemconfig = SystemConfigOper()
wordsmatcher = WordsMatcher() wordsmatcher = WordsMatcher()
try:
for domain, contexts in processed_torrents.items(): for domain, contexts in processed_torrents.items():
if global_vars.is_system_stopped: if global_vars.is_system_stopped:
break break
if domains and domain not in domains: if domains and domain not in domains:
continue continue
logger.debug(f'开始匹配站点:{domain},共缓存了 {len(contexts)} 个种子...') logger.debug(f'开始匹配站点:{domain},共缓存了 {len(contexts)} 个种子...')
try:
for context in contexts: for context in contexts:
if global_vars.is_system_stopped: if global_vars.is_system_stopped:
break break
@@ -777,6 +784,12 @@ class SubscribeChain(ChainBase):
if subscribe.episode_group: if subscribe.episode_group:
torrent_mediainfo.episode_group = subscribe.episode_group torrent_mediainfo.episode_group = subscribe.episode_group
_match_context.append(_context) _match_context.append(_context)
finally:
contexts.clear()
del contexts
finally:
processed_torrents.clear()
del processed_torrents
if not _match_context: if not _match_context:
# 未匹配到资源 # 未匹配到资源
@@ -802,11 +815,11 @@ class SubscribeChain(ChainBase):
if subscribe: if subscribe:
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
downloads=downloads, lefts=lefts) downloads=downloads, lefts=lefts)
logger.debug(f"match Lock released at {datetime.now()}")
finally: finally:
subscribes.clear() subscribes.clear()
processed_torrents.clear() del subscribes
logger.debug(f"match Lock released at {datetime.now()}")
def check(self): def check(self):
""" """
+2
View File
@@ -131,6 +131,7 @@ class TorrentsChain(ChainBase):
ret_torrents.append(torrentinfo) ret_torrents.append(torrentinfo)
finally: finally:
rss_items.clear() rss_items.clear()
del rss_items
return ret_torrents return ret_torrents
def refresh(self, stype: Optional[str] = None, sites: List[int] = None) -> Dict[str, List[Context]]: def refresh(self, stype: Optional[str] = None, sites: List[int] = None) -> Dict[str, List[Context]]:
@@ -220,6 +221,7 @@ class TorrentsChain(ChainBase):
torrents_cache[domain] = torrents_cache[domain][-settings.CONF["torrents"]:] torrents_cache[domain] = torrents_cache[domain][-settings.CONF["torrents"]:]
finally: finally:
torrents.clear() torrents.clear()
del torrents
else: else:
logger.info(f'{indexer.get("name")} 没有获取到种子') logger.info(f'{indexer.get("name")} 没有获取到种子')
+3
View File
@@ -864,6 +864,7 @@ class TransferChain(ChainBase, metaclass=Singleton):
self.transfer_completed(hashs=torrent.hash, downloader=torrent.downloader) self.transfer_completed(hashs=torrent.hash, downloader=torrent.downloader)
finally: finally:
torrents.clear() torrents.clear()
del torrents
# 结束 # 结束
logger.info("所有下载器中下载完成的文件已整理完成") logger.info("所有下载器中下载完成的文件已整理完成")
@@ -1144,6 +1145,7 @@ class TransferChain(ChainBase, metaclass=Singleton):
transfer_tasks.append(transfer_task) transfer_tasks.append(transfer_task)
finally: finally:
file_items.clear() file_items.clear()
del file_items
# 实时整理 # 实时整理
if transfer_tasks: if transfer_tasks:
@@ -1187,6 +1189,7 @@ class TransferChain(ChainBase, metaclass=Singleton):
processed_num += 1 processed_num += 1
finally: finally:
transfer_tasks.clear() transfer_tasks.clear()
del transfer_tasks
# 整理结束 # 整理结束
__end_msg = f"整理队列处理完成,共整理 {total_num} 个文件,失败 {fail_num}" __end_msg = f"整理队列处理完成,共整理 {total_num} 个文件,失败 {fail_num}"
+5
View File
@@ -182,6 +182,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, f"下载任务已存在" return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, f"下载任务已存在"
finally: finally:
torrents.clear() torrents.clear()
del torrents
return None, None, None, f"添加种子任务失败:{content}" return None, None, None, f"添加种子任务失败:{content}"
else: else:
# 获取种子Hash # 获取种子Hash
@@ -211,6 +212,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
sucess_epidised = list(set(sucess_epidised).union(set(meta_info.episode_list))) sucess_epidised = list(set(sucess_epidised).union(set(meta_info.episode_list)))
finally: finally:
torrent_files.clear() torrent_files.clear()
del torrent_files
if sucess_epidised and file_ids: if sucess_epidised and file_ids:
# 选择文件 # 选择文件
server.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0) server.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0)
@@ -269,6 +271,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
)) ))
finally: finally:
torrents.clear() torrents.clear()
del torrents
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:
# 获取已完成且未整理的 # 获取已完成且未整理的
for name, server in servers.items(): for name, server in servers.items():
@@ -293,6 +296,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
)) ))
finally: finally:
torrents.clear() torrents.clear()
del torrents
elif status == TorrentStatus.DOWNLOADING: elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务 # 获取正在下载的任务
for name, server in servers.items(): for name, server in servers.items():
@@ -319,6 +323,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
)) ))
finally: finally:
torrents.clear() torrents.clear()
del torrents
else: else:
return None return None
return ret_torrents # noqa return ret_torrents # noqa
+1
View File
@@ -105,6 +105,7 @@ class Qbittorrent:
results.append(torrent) results.append(torrent)
finally: finally:
torrents.clear() torrents.clear()
del torrents
return results, False return results, False
return torrents or [], False return torrents or [], False
except Exception as err: except Exception as err:
+5
View File
@@ -184,6 +184,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, f"下载任务已存在" return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, f"下载任务已存在"
finally: finally:
torrents.clear() torrents.clear()
del torrents
return None, None, None, f"添加种子任务失败:{content}" return None, None, None, f"添加种子任务失败:{content}"
else: else:
torrent_hash = torrent.hashString torrent_hash = torrent.hashString
@@ -215,6 +216,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
server.start_torrents(torrent_hash) server.start_torrents(torrent_hash)
finally: finally:
torrent_files.clear() torrent_files.clear()
del torrent_files
return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, "添加下载任务成功" return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, "添加下载任务成功"
else: else:
return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, "添加下载任务成功" return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, "添加下载任务成功"
@@ -255,6 +257,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
)) ))
finally: finally:
torrents.clear() torrents.clear()
del torrents
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:
# 获取已完成且未整理的 # 获取已完成且未整理的
for name, server in servers.items(): for name, server in servers.items():
@@ -281,6 +284,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
)) ))
finally: finally:
torrents.clear() torrents.clear()
del torrents
elif status == TorrentStatus.DOWNLOADING: elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务 # 获取正在下载的任务
for name, server in servers.items(): for name, server in servers.items():
@@ -306,6 +310,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
)) ))
finally: finally:
torrents.clear() torrents.clear()
del torrents
else: else:
return None return None
return ret_torrents # noqa return ret_torrents # noqa
+1
View File
@@ -106,6 +106,7 @@ class Transmission:
ret_torrents.append(torrent) ret_torrents.append(torrent)
finally: finally:
torrents.clear() torrents.clear()
del torrents
return ret_torrents, False return ret_torrents, False
def get_completed_torrents(self, ids: Union[str, list] = None, def get_completed_torrents(self, ids: Union[str, list] = None,