mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-05-11 10:00:18 +08:00
fix: 预检查收藏夹内容类型,支持写入 nfo
This commit is contained in:
47
nfo.py
Normal file
47
nfo.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from dataclasses import dataclass
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass
|
||||
class Actor:
|
||||
name: str
|
||||
|
||||
def to_xml(self) -> str:
|
||||
return f"""
|
||||
<actor>
|
||||
<name>{self.name}</name>
|
||||
</actor>
|
||||
""".strip(
|
||||
"\n"
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class EpisodeInfo:
|
||||
title: str
|
||||
plot: str
|
||||
actor: list[Actor]
|
||||
bvid: str
|
||||
aired: datetime.datetime
|
||||
|
||||
def write_nfo(self, path: Path) -> None:
|
||||
with path.open("w", encoding="utf-8") as f:
|
||||
f.write(self.to_xml())
|
||||
|
||||
def to_xml(self) -> str:
|
||||
actor = "\n".join(_.to_xml() for _ in self.actor)
|
||||
return f"""
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<episodedetails>
|
||||
<plot><![CDATA[{self.plot}]]></plot>
|
||||
<outline />
|
||||
<title>{self.title}</title>
|
||||
{actor}
|
||||
<year>{self.aired.year}</year>
|
||||
<uniqueid type="bilibili">{self.bvid}</uniqueid>
|
||||
<aired>{self.aired.strftime("%Y-%m-%d")}</aired>
|
||||
</episodedetails>
|
||||
""".strip(
|
||||
"\n"
|
||||
)
|
||||
Reference in New Issue
Block a user