feat: improve torrent resource presentation

这个提交存在于:
Codex 2026-07-22 23:12:18 +08:00
父节点 3fef03a851
当前提交 8d1c2088c1
共有 4 个文件被更改,包括 47 次插入 和 13 次删除

查看文件

@ -40,7 +40,7 @@ def _media_result_chain(results: list[dict[str, object]]) -> list[object]:
"astrbot_plugin_moviepilot",
"AstrBot MoviePilot Contributors",
"在 AstrBot 中通过命令和 LLM 控制 MoviePilot。",
"0.14.0",
"0.15.0",
)
class MoviePilotPlugin(star.Star):
"""MoviePilot integration entrypoint."""

查看文件

@ -187,16 +187,50 @@ def format_media_results(results: list[dict[str, Any]]) -> str:
lines.append("可继续使用:/mp resources <编号> 或 /mp subscribe <编号>")
return "\n\n".join(lines)
def _format_resource_size(value: Any) -> str:
if value in (None, "", 0, 0.0):
return "\u672a\u77e5"
if isinstance(value, (int, float)):
size = float(value)
if size >= 1024:
return f"{size / 1024:.2f} GB"
return f"{size:.2f} MB"
return str(value)
def format_resource_result_item(index: int, item: Mapping[str, Any]) -> str:
title = _first_value(item, "title", "name") or "\u672a\u547d\u540d\u8d44\u6e90"
site = _first_value(item, "site_name", "site") or "\u672a\u77e5\u7ad9\u70b9"
quality = _first_value(item, "quality", "resolution", "category") or "\u672a\u77e5\u8d28\u91cf"
size = _format_resource_size(_first_value(item, "size", "length"))
seeders = _first_value(item, "seeders", "seed", "seeds")
peers = _first_value(item, "peers", "leechers", "leeches")
seed_text = seeders if seeders is not None else "\u672a\u77e5"
peer_text = peers if peers is not None else "\u672a\u77e5"
pubdate = _first_value(item, "pubdate", "publish_time", "published_at") or "\u672a\u77e5"
free = _first_value(item, "freedate", "free", "is_free", "volume_factor")
free_text = "\u662f" if free is True or (isinstance(free, str) and free.lower() in {"free", "yes", "true"}) else "\u5426"
colon = "\uFF1A"
lines = [
f"\u8d44\u6e90 {index}",
f"\u540d\u79f0{colon}{title}",
f"\u7ad9\u70b9{colon}{site}",
f"\u8d28\u91cf{colon}{quality}",
f"\u5927\u5c0f{colon}{size}",
f"\u505a\u79cd{colon}{seed_text} / \u4e0b\u8f7d{colon}{peer_text}",
f"\u53d1\u5e03\u65f6\u95f4{colon}{pubdate}",
f"\u514d\u8d39{colon}{free_text}",
]
if not _first_value(item, "enclosure", "page_url", "download_url", "url"):
lines.append(f"\u63d0\u793a{colon}\u8be5\u8d44\u6e90\u7f3a\u5c11\u53ef\u63d0\u4ea4\u7684\u4e0b\u8f7d\u94fe\u63a5\uFF0C\u53ef\u80fd\u65e0\u6cd5\u76f4\u63a5\u4e0b\u8f7d")
return chr(10).join(lines)
def format_resource_results(results: list[dict[str, Any]]) -> str:
if not results:
return "暂未找到资源。可以使用 /mp subscribe <媒体编号> 订阅该媒体。"
lines = ["资源搜索结果:"]
return "\u6682\u672a\u627e\u5230\u8d44\u6e90\u3002\u53ef\u4ee5\u4f7f\u7528 /mp subscribe <\u5a92\u4f53\u7f16\u53f7> \u8ba2\u9605\u8be5\u5a92\u4f53\u3002"
lines = ["\u8d44\u6e90\u641c\u7d22\u7ed3\u679c\uFF1A"]
for index, item in enumerate(results, start=1):
title = item.get("title") or item.get("name") or "未命名资源"
site = item.get("site_name") or item.get("site") or "未知站点"
size = item.get("size") or item.get("length") or ""
quality = item.get("quality") or item.get("resolution") or ""
details = " / ".join(str(value) for value in (site, size, quality) if value)
lines.append(f"{index}. {title}({details})")
lines.append("可使用 /mp download <编号> 选择资源下载。")
return "\n".join(lines)
lines.append(format_resource_result_item(index, item))
lines.append("\u53ef\u4f7f\u7528 /mp download <\u7f16\u53f7> \u9009\u62e9\u8d44\u6e90\u4e0b\u8f7d\u3002")
return (chr(10) + chr(10)).join(lines)

查看文件

@ -2,7 +2,7 @@ name: astrbot_plugin_moviepilot
display_name: MoviePilot 控制
description: 在 AstrBot 中通过命令和 LLM 控制 MoviePilot。
short_desc: 搜索影视、订阅、下载和接收 MoviePilot 通知。
version: 0.14.0
version: 0.15.0
author: AstrBot MoviePilot Contributors
repo: https://github.com/jxxghp/MoviePilot
astrbot_version: ">=4.16,<5"

查看文件

@ -13,7 +13,7 @@ def test_metadata_contains_required_plugin_fields() -> None:
)
assert metadata["name"] == "astrbot_plugin_moviepilot"
assert metadata["version"] == "0.14.0"
assert metadata["version"] == "0.15.0"
assert metadata["astrbot_version"] == ">=4.16,<5"
assert "aiocqhttp" in metadata["support_platforms"]
assert "telegram" in metadata["support_platforms"]