media: change subtitles from a str to a list
- ID
eecb946- date
2026-02-20 05:20:51+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
306f294- message
media: change subtitles from a str to a list- changed files
4 files, 25 additions, 8 deletions
Changed files
CHANGELOG.md (2597) → CHANGELOG.md (2746)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24416ac..86dea42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## v23 - 2026-02-20
+
+Change the format of `VideoEntity.subtitles` to be a list of `SubtitlesEntity`, so a single video can have multiple subtitles.
+
## v22 - 2026-01-11
Remove the `start_radio` parameter in `clean_youtube_url()`.
src/chives/__init__.py (391) → src/chives/__init__.py (391)
diff --git a/src/chives/__init__.py b/src/chives/__init__.py
index d7972cc..88f2769 100644
--- a/src/chives/__init__.py
+++ b/src/chives/__init__.py
@@ -11,4 +11,4 @@ I share across multiple sites.
"""
-__version__ = "22"
+__version__ = "23"
src/chives/media.py (10314) → src/chives/media.py (10520)
diff --git a/src/chives/media.py b/src/chives/media.py
index 46139dc..c7990ef 100644
--- a/src/chives/media.py
+++ b/src/chives/media.py
@@ -100,6 +100,15 @@ class ImageEntity(TypedDict):
source_url: NotRequired[str]
+class SubtitlesEntity(TypedDict):
+ """
+ SubtitlesEntity describes a set of subtitles.
+ """
+
+ path: str
+ label: str
+
+
class VideoEntity(TypedDict):
"""
VideoEntity contains all the fields I need to render a video
@@ -122,7 +131,7 @@ class VideoEntity(TypedDict):
duration: str
# Path to the subtitles for the video, if available
- subtitles_path: NotRequired[str]
+ subtitles: NotRequired[list[SubtitlesEntity]]
# The source URL of the image, if available
source_url: NotRequired[str]
@@ -148,8 +157,10 @@ def get_media_paths(e: MediaEntity) -> set[Path]:
if e["type"] == "video":
result.add(e["path"])
+
try:
- result.add(e["subtitles_path"])
+ for se in e["subtitles"]:
+ result.add(se["path"])
except KeyError:
pass
for p in get_media_paths(e["poster"]):
@@ -252,7 +263,7 @@ def create_video_entity(
}
if subtitles_path:
- entity["subtitles_path"] = str(subtitles_path)
+ entity["subtitles"] = [{"path": str(subtitles_path), "label": "English"}]
if source_url:
entity["source_url"] = source_url
tests/test_media.py (14662) → tests/test_media.py (14722)
diff --git a/tests/test_media.py b/tests/test_media.py
index 8b44ea4..d96e68c 100644
--- a/tests/test_media.py
+++ b/tests/test_media.py
@@ -269,10 +269,12 @@ class TestCreateVideoEntity:
autoplay=True,
)
- assert (
- entity["subtitles_path"]
- == "tests/fixtures/media/Sintel_360_10s_1MB_H264.en.vtt"
- )
+ assert entity["subtitles"] == [
+ {
+ "path": "tests/fixtures/media/Sintel_360_10s_1MB_H264.en.vtt",
+ "label": "English",
+ }
+ ]
assert entity["source_url"] == "https://test-videos.co.uk/sintel/mp4-h264"
assert entity["autoplay"]