Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add subtitle download support #12

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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