Skip to content

Commit

Permalink
feat: add subtitle download support
Browse files Browse the repository at this point in the history
Downloads subtitles in VTT format if available alongside the video.
  • Loading branch information
ivansaul committed Nov 17, 2024
1 parent 8d3e854 commit 436ffd7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/platzi/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 436ffd7

Please sign in to comment.