mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-08 17:09:14 +08:00
fix: 对 xml 中的文本内容转义,避免特殊字符影响
This commit is contained in:
@@ -65,10 +65,6 @@ class FavoriteItem(Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (("bvid", "favorite_list_id"),)
|
unique_together = (("bvid", "favorite_list_id"),)
|
||||||
|
|
||||||
@property
|
|
||||||
def safe_name(self) -> str:
|
|
||||||
return self.name.replace("/", "_")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tmp_video_path(self) -> Path:
|
def tmp_video_path(self) -> Path:
|
||||||
return Path(settings.path_mapper[self.favorite_list_id]) / f"tmp_{self.bvid}_video"
|
return Path(settings.path_mapper[self.favorite_list_id]) / f"tmp_{self.bvid}_video"
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ class Base:
|
|||||||
def to_xml(self) -> str:
|
def to_xml(self) -> str:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def escape(s: str) -> str:
|
||||||
|
"""转义 xml 特殊字符"""
|
||||||
|
return s.translate(str.maketrans({"<": "<", ">": ">", "&": "&", "'": "'", '"': """}))
|
||||||
|
|
||||||
async def to_file(self, path: Path) -> None:
|
async def to_file(self, path: Path) -> None:
|
||||||
"""把 xml 写入文件"""
|
"""把 xml 写入文件"""
|
||||||
async with aopen(path, "w", encoding="utf-8") as f:
|
async with aopen(path, "w", encoding="utf-8") as f:
|
||||||
@@ -39,7 +44,7 @@ class EpisodeInfo(Base):
|
|||||||
<episodedetails>
|
<episodedetails>
|
||||||
<plot />
|
<plot />
|
||||||
<outline />
|
<outline />
|
||||||
<title>{self.title}</title>
|
<title>{self.escape(self.title)}</title>
|
||||||
<season>{self.season}</season>
|
<season>{self.season}</season>
|
||||||
<episode>{self.episode}</episode>
|
<episode>{self.episode}</episode>
|
||||||
</episodedetails>
|
</episodedetails>
|
||||||
@@ -59,7 +64,7 @@ class Actor(Base):
|
|||||||
return f"""
|
return f"""
|
||||||
<actor>
|
<actor>
|
||||||
<name>{self.name}</name>
|
<name>{self.name}</name>
|
||||||
<role>{self.role}</role>
|
<role>{self.escape(self.role)}</role>
|
||||||
</actor>
|
</actor>
|
||||||
""".strip()
|
""".strip()
|
||||||
|
|
||||||
@@ -88,13 +93,15 @@ class MovieInfo(Base):
|
|||||||
|
|
||||||
def to_xml(self) -> str:
|
def to_xml(self) -> str:
|
||||||
actor = "\n".join(_.to_xml() for _ in self.actor)
|
actor = "\n".join(_.to_xml() for _ in self.actor)
|
||||||
tags = "\n".join(f" <genre>{_}</genre>" for _ in self.tags) if isinstance(self.tags, list) else ""
|
tags = (
|
||||||
|
"\n".join(f" <genre>{self.escape(_)}</genre>" for _ in self.tags) if isinstance(self.tags, list) else ""
|
||||||
|
)
|
||||||
return f"""
|
return f"""
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
<movie>
|
<movie>
|
||||||
<plot><![CDATA[{self.plot}]]></plot>
|
<plot><![CDATA[{self.escape(self.plot)}]]></plot>
|
||||||
<outline />
|
<outline />
|
||||||
<title>{self.title}</title>
|
<title>{self.escape(self.title)}</title>
|
||||||
{actor}
|
{actor}
|
||||||
<year>{self.aired.year}</year>
|
<year>{self.aired.year}</year>
|
||||||
{tags}
|
{tags}
|
||||||
@@ -126,13 +133,15 @@ class TVShowInfo(Base):
|
|||||||
|
|
||||||
def to_xml(self) -> str:
|
def to_xml(self) -> str:
|
||||||
actor = "\n".join(_.to_xml() for _ in self.actor)
|
actor = "\n".join(_.to_xml() for _ in self.actor)
|
||||||
tags = "\n".join(f" <genre>{_}</genre>" for _ in self.tags) if isinstance(self.tags, list) else ""
|
tags = (
|
||||||
|
"\n".join(f" <genre>{self.escape(_)}</genre>" for _ in self.tags) if isinstance(self.tags, list) else ""
|
||||||
|
)
|
||||||
return f"""
|
return f"""
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
<tvshow>
|
<tvshow>
|
||||||
<plot><![CDATA[{self.plot}]]></plot>
|
<plot><![CDATA[{self.escape(self.plot)}]]></plot>
|
||||||
<outline />
|
<outline />
|
||||||
<title>{self.title}</title>
|
<title>{self.escape(self.title)}</title>
|
||||||
{actor}
|
{actor}
|
||||||
<year>{self.aired.year}</year>
|
<year>{self.aired.year}</year>
|
||||||
{tags}
|
{tags}
|
||||||
|
|||||||
Reference in New Issue
Block a user