mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-12 19:21:05 +08:00
feat: accelerate site indexer parsing with rust
This commit is contained in:
@@ -12,6 +12,7 @@ from pyquery import PyQuery
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
from app.schemas.types import MediaType
|
||||
from app.utils import rust_accel
|
||||
from app.utils.http import RequestUtils, AsyncRequestUtils
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.url import UrlUtils
|
||||
@@ -737,6 +738,17 @@ class SiteSpider:
|
||||
self.is_error = True
|
||||
return []
|
||||
|
||||
rust_torrents = rust_accel.parse_indexer_torrents(
|
||||
html_text=html_text,
|
||||
domain=self.domain,
|
||||
list_config=self.list,
|
||||
fields=self.fields,
|
||||
category=self.category,
|
||||
result_num=self.result_num
|
||||
)
|
||||
if rust_torrents is not None:
|
||||
return rust_torrents
|
||||
|
||||
# 清空旧结果
|
||||
self.torrents_info_array = []
|
||||
html_doc = None
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import List, Optional
|
||||
|
||||
from app.log import logger
|
||||
|
||||
@@ -39,6 +39,34 @@ def parse_filter_rule(expression: str) -> Optional[list]:
|
||||
return None
|
||||
|
||||
|
||||
def parse_indexer_torrents(
|
||||
html_text: str,
|
||||
domain: str,
|
||||
list_config: dict,
|
||||
fields: dict,
|
||||
category: Optional[dict] = None,
|
||||
result_num: int = 100
|
||||
) -> Optional[List[dict]]:
|
||||
"""
|
||||
使用 Rust 批量解析普通配置站点种子列表,不可用时返回 None。
|
||||
"""
|
||||
if not _moviepilot_rust:
|
||||
return None
|
||||
try:
|
||||
return _moviepilot_rust.parse_indexer_torrents_fast(
|
||||
html_text,
|
||||
domain,
|
||||
list_config,
|
||||
fields,
|
||||
category,
|
||||
result_num
|
||||
)
|
||||
except BaseException as err:
|
||||
_raise_non_rust_panic(err)
|
||||
logger.debug(f"Rust 站点列表解析失败,使用 Python 解析兜底:{err}")
|
||||
return None
|
||||
|
||||
|
||||
def _raise_non_rust_panic(err: BaseException) -> None:
|
||||
"""
|
||||
只吞掉 Rust 扩展 panic/异常,保留用户中断和进程退出语义。
|
||||
|
||||
Reference in New Issue
Block a user