import datetime
from dataclasses import dataclass
from pathlib import Path
from utils import aopen
@dataclass
class Actor:
name: str
role: str
def to_xml(self) -> str:
return f"""
{self.name}
{self.role}
""".strip(
"\n"
)
@dataclass
class EpisodeInfo:
title: str
plot: str
tags: list[str]
actor: list[Actor]
bvid: str
aired: datetime.datetime
async def write_nfo(self, path: Path) -> None:
async with aopen(path, "w", encoding="utf-8") as f:
await f.write(self.to_xml())
def to_xml(self) -> str:
actor = "\n".join(_.to_xml() for _ in self.actor)
tags = (
"\n".join(f" {_}" for _ in self.tags)
if isinstance(self.tags, list)
else ""
)
return f"""
{self.title}
{actor}
{self.aired.year}
{tags}
{self.bvid}
{self.aired.strftime("%Y-%m-%d")}
""".strip(
"\n"
)