Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grab TV series from iVysilani with CC and AD
#!/usr/bin/env python3
import subprocess
import youtube_dl
import click
from pprint import pprint
@click.command()
@click.option("--first", type=int, default=1)
@click.option("--last", type=int, default=1)
@click.option("--outbase", default="E{:02d}.mkv")
@click.argument("base_url")
def main(base_url, first, last, outbase):
"""Download TV series from iVysilani"""
fnames = {
"video": ".mp4", "audio": ".m4a", "ad": ".m4a", "cc": ".srt"
}
def my_hook(d):
if d["status"] == "finished":
fn = d["filename"]
if fn.endswith("-NA.mp4"):
fnames["video"] = fn
fnames["cc"] = fn[:-3] + "cs.srt"
elif fn.endswith("-ces.m4a"):
fnames["audio"] = fn
elif fn.endswith("-que.m4a"):
fnames["ad"] = fn
ydl_opts = {
"format": "bestvideo,bestaudio,dash-audioDescription-1002-1507",
"writesubtitles": True,
"outtmpl": "%(title)s-%(id)s-%(language)s.%(ext)s",
"progress_hooks": [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
for i in range(first, last+1):
ydl.download([base_url.format(i)])
outname = outbase.format(i)
subprocess.run([
"mkvmerge", "-o", outname, fnames["video"],
"--language", "0:cze", fnames["audio"],
"--language", "0:cze", "--track-name",
"0:\"audio description\"", fnames["ad"],
"--default-track", "0:0",
"--language", "0:cze", "--track-name",
"0:\"closed captions\"", fnames["cc"],
])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.