import datetime
from dataclasses import dataclass
from pathlib import Path
@dataclass
class Actor:
name: str
role: str
thumb: Path
def to_xml(self) -> str:
return f"""
{self.name}
{self.role}
{self.thumb.resolve()}
""".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"""
{self.title}
{actor}
{self.aired.year}
{self.bvid}
{self.aired.strftime("%Y-%m-%d")}
""".strip(
"\n"
)