Skip to content

Instantly share code, notes, and snippets.

@oskar456
Created March 10, 2019 21:03
Show Gist options
  • Save oskar456/1689f878c75e2dee06501a2aff2f3ee9 to your computer and use it in GitHub Desktop.
Save oskar456/1689f878c75e2dee06501a2aff2f3ee9 to your computer and use it in GitHub Desktop.
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