Support fetch movie metadata from bangumi.tv

This commit is contained in:
Xylitol
2024-01-23 18:16:01 +08:00
parent 6395803f8e
commit 7c3725b519
2 changed files with 124 additions and 3 deletions

View File

@ -0,0 +1,106 @@
{
"type": "movie",
"site": "bangumi.tv",
"steps": [
{
"doh": {
"host": "api.bgm.tv"
}
},
{
"http": {
"url": "https://api.bgm.tv/search/subject/{title}?type=2&start=0&max_results={limit}",
"method": "GET",
"headers": {
"User-Agent": "C5H12O5/syno-videoinfo-plugin{version} (https://github.com/C5H12O5/syno-videoinfo-plugin)"
},
"result": "metadata"
}
},
{
"collect": {
"source": "metadata",
"into": {
"ids": "['xp_texts', './list//id']"
}
}
},
{
"loop": {
"source": "ids",
"item": "id",
"steps": [
{
"http": {
"url": "https://api.bgm.tv/v0/subjects/{id}",
"method": "GET",
"headers": {
"User-Agent": "C5H12O5/syno-videoinfo-plugin{$parent[version]} (https://github.com/C5H12O5/syno-videoinfo-plugin)"
},
"result": "subject"
}
},
{
"collect": {
"source": "subject",
"into": {
"movie": {
"title": "['xp_text', './name_cn']",
"tagline": "['xp_text', './name']",
"original_available": "['xp_text', './date']",
"summary": "['xp_text', './summary']",
"certificate": "",
"genre": "['xp_texts', './tags//name']",
"actor": [],
"writer": "['re_matches', '\"key\":\"原作\",\"value\":\"([^\"]*?)\"']",
"director": "['re_matches', '\"key\":\"导演\",\"value\":\"([^\"]*?)\"']",
"extra": {
"[plugin_id]": {
"rating": {
"[plugin_id]": "['xp_text', './rating//score', 'float']"
},
"poster": [
"['xp_text', './images//large']"
],
"backdrop": [
"['xp_text', './images//large']"
]
}
}
},
"publish_date": "['xp_text', './date']",
"available_date": "{$parent[available]}"
}
}
},
{
"http": {
"url": "https://api.bgm.tv/v0/subjects/{id}/characters",
"method": "GET",
"headers": {
"User-Agent": "C5H12O5/syno-videoinfo-plugin{$parent[version]} (https://github.com/C5H12O5/syno-videoinfo-plugin)"
},
"result": "characters"
}
},
{
"collect": {
"source": "characters",
"into": {
"movie": {
"actor": "['xp_texts', './/actors//name']"
}
}
}
},
{
"retval": {
"source": "movie",
"compare": "['publish_date', '>=', 'available_date']"
}
}
]
}
}
]
}

View File

@ -58,7 +58,8 @@ def scrape(plugin_id: str) -> str:
"available": jsoninput.get("original_available", None),
"year": str(jsoninput.get("original_available", ""))[:4],
"lang": language,
"limit": maxlimit
"limit": maxlimit,
"version": _version(plugin_id),
}
# load and execute scrape flows using multithreading
@ -98,11 +99,25 @@ def _start(flow: "ScrapeFlow", limit: int):
_logger.error("Failed to scrape from %s", flow.site, exc_info=True)
def _version(plugin_id: str) -> str:
"""Split the plugin ID to get the version."""
if "-" in plugin_id:
version = plugin_id.split("-")[-1]
if version != "plugin":
return f"/{version}"
return ""
class ScrapeFlow:
"""A flow of steps to scrape video information."""
def __init__(self, site: str, steps: list, context: dict,
priority: Optional[int]):
def __init__(
self,
site: str,
steps: list,
context: dict,
priority: Optional[int],
):
self.site = site
self.steps = steps
self.context = context