From 0dd561a11880ab4cfce4b6631b385b414b953f93 Mon Sep 17 00:00:00 2001 From: davidemarcoli Date: Fri, 11 Oct 2024 11:51:01 +0200 Subject: [PATCH] fix: serialize subtitles for api response --- src/program/media/item.py | 2 +- src/program/media/subtitle.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/program/media/item.py b/src/program/media/item.py index 5664d000..c633248c 100644 --- a/src/program/media/item.py +++ b/src/program/media/item.py @@ -265,7 +265,7 @@ def to_extended_dict(self, abbreviated_children=False, with_streams=True): dict["file"] = self.file if hasattr(self, "file") else None dict["folder"] = self.folder if hasattr(self, "folder") else None dict["symlink_path"] = self.symlink_path if hasattr(self, "symlink_path") else None - dict["subtitles"] = getattr(self, "subtitles", []) + dict["subtitles"] = [subtitle.to_dict() for subtitle in self.subtitles] if hasattr(self, "subtitles") else [] return dict def __iter__(self): diff --git a/src/program/media/subtitle.py b/src/program/media/subtitle.py index a8a64799..ff2f00ab 100644 --- a/src/program/media/subtitle.py +++ b/src/program/media/subtitle.py @@ -35,4 +35,12 @@ def remove(self): if self.file and Path(self.file).exists(): Path(self.file).unlink() self.file = None - return self \ No newline at end of file + return self + + def to_dict(self): + return { + "id": str(self._id), + "language": self.language, + "file": self.file, + "parent_id": self.parent_id + } \ No newline at end of file