mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 00:16:57 +08:00
fix: handle invalid mtorrent seeding items
This commit is contained in:
@@ -120,16 +120,27 @@ class MTorrentSiteUserInfo(SiteParserBase):
|
|||||||
seeding_info = json.loads(html_text)
|
seeding_info = json.loads(html_text)
|
||||||
if not seeding_info or seeding_info.get("code") != "0":
|
if not seeding_info or seeding_info.get("code") != "0":
|
||||||
return None
|
return None
|
||||||
torrents = seeding_info.get("data", {}).get("data", [])
|
seeding_data = seeding_info.get("data") or {}
|
||||||
|
if not isinstance(seeding_data, dict):
|
||||||
|
return None
|
||||||
|
torrents = seeding_data.get("data") or []
|
||||||
|
if not isinstance(torrents, list):
|
||||||
|
return None
|
||||||
|
page_seeding = 0
|
||||||
page_seeding_size = 0
|
page_seeding_size = 0
|
||||||
page_seeding_info = []
|
page_seeding_info = []
|
||||||
for info in torrents:
|
for info in torrents:
|
||||||
torrent = info.get("torrent", {})
|
if not isinstance(info, dict):
|
||||||
|
continue
|
||||||
|
torrent = info.get("torrent")
|
||||||
|
if not isinstance(torrent, dict):
|
||||||
|
continue
|
||||||
size = int(torrent.get("size") or '0')
|
size = int(torrent.get("size") or '0')
|
||||||
seeders = int(torrent.get("source") or '0')
|
seeders = int(torrent.get("source") or '0')
|
||||||
|
page_seeding += 1
|
||||||
page_seeding_size += size
|
page_seeding_size += size
|
||||||
page_seeding_info.append([seeders, size])
|
page_seeding_info.append([seeders, size])
|
||||||
self.seeding += len(torrents)
|
self.seeding += page_seeding
|
||||||
self.seeding_size += page_seeding_size
|
self.seeding_size += page_seeding_size
|
||||||
self.seeding_info.extend(page_seeding_info)
|
self.seeding_info.extend(page_seeding_info)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import json
|
||||||
|
|
||||||
|
from app.modules.indexer.parser.mtorrent import MTorrentSiteUserInfo
|
||||||
|
|
||||||
|
|
||||||
|
def _build_parser() -> MTorrentSiteUserInfo:
|
||||||
|
"""
|
||||||
|
构造 MTorrent 解析器测试实例。
|
||||||
|
"""
|
||||||
|
return MTorrentSiteUserInfo(
|
||||||
|
site_name="MTorrent",
|
||||||
|
url="https://example.com/",
|
||||||
|
site_cookie="",
|
||||||
|
apikey="apikey",
|
||||||
|
token=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mtorrent_seeding_skips_invalid_torrent_items(monkeypatch):
|
||||||
|
"""
|
||||||
|
MTorrent 返回空种子对象时应跳过异常条目并只统计有效做种。
|
||||||
|
"""
|
||||||
|
parser = _build_parser()
|
||||||
|
parser.userid = "1"
|
||||||
|
parser._torrent_seeding_params = {
|
||||||
|
"pageNumber": 1,
|
||||||
|
"pageSize": 200,
|
||||||
|
"type": "SEEDING",
|
||||||
|
"userid": parser.userid,
|
||||||
|
}
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
parser,
|
||||||
|
"_get_page_content",
|
||||||
|
lambda **_: json.dumps({"data": {"seeder": 1}}),
|
||||||
|
)
|
||||||
|
html_text = json.dumps(
|
||||||
|
{
|
||||||
|
"code": "0",
|
||||||
|
"data": {
|
||||||
|
"data": [
|
||||||
|
{"torrent": None},
|
||||||
|
{"torrent": "invalid"},
|
||||||
|
None,
|
||||||
|
{"torrent": {"size": "1024", "source": "3"}},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
next_page = parser._parse_user_torrent_seeding_info(html_text)
|
||||||
|
|
||||||
|
assert next_page is None
|
||||||
|
assert parser.seeding == 1
|
||||||
|
assert parser.seeding_size == 1024
|
||||||
|
assert parser.seeding_info == [[3, 1024]]
|
||||||
Reference in New Issue
Block a user