From 436ffd7f20f3eac409108875e0cea45482feceb8 Mon Sep 17 00:00:00 2001 From: ivansaul Date: Sun, 17 Nov 2024 15:25:48 -0500 Subject: [PATCH] feat: add subtitle download support Downloads subtitles in VTT format if available alongside the video. --- src/platzi/async_api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platzi/async_api.py b/src/platzi/async_api.py index ae56439..8ac28f0 100644 --- a/src/platzi/async_api.py +++ b/src/platzi/async_api.py @@ -10,7 +10,7 @@ from .logger import Logger from .m3u8 import m3u8_dl from .models import TypeUnit, User -from .utils import progressive_scroll, slugify +from .utils import download, progressive_scroll, slugify def login_required(func): @@ -155,11 +155,18 @@ async def download(self, url: str, **kwargs): unit = await get_unit(self.context, unit_url) name = f"{jdx:02}_{slugify(unit.title)}" + # download video if unit.video: dst = CHAP_DIR / f"{name}.mp4" Logger.print(f"[{name}.mp4]", "[DOWNLOADING][VIDEO]") await m3u8_dl(unit.video.url, dst.as_posix(), headers=HEADERS) + if unit.video.subtitles_url: + dst = CHAP_DIR / f"{name}.vtt" + Logger.print(f"[{name}.vtt]", "[DOWNLOADING][SUBTITLES]") + await download(unit.video.subtitles_url, dst) + + # download lecture if unit.type == TypeUnit.LECTURE: Logger.print(f"[{name}.mhtml]", "[DOWNLOADING][LECTURE]") await self.save_page(