Skip to content

Instantly share code, notes, and snippets.

@pleonex
Created November 16, 2020 23:20
Show Gist options
  • Save pleonex/bbba5c093820c0a06a19df1c3f308612 to your computer and use it in GitHub Desktop.
Save pleonex/bbba5c093820c0a06a19df1c3f308612 to your computer and use it in GitHub Desktop.
Script to download videos and subtitles from Viki
import youtube_dl
url = 'THE_URL'
def download_episode(ydl, url):
"""Download the info (url in MPD) to get the URL and update the title."""
info = ydl.extract_info(url, download=False, process=False)
print(f"**{info['title']}**")
# Download substitles
subs = ydl.process_subtitles(info["id"], info["subtitles"], False)
# Get video URL from MPD
video_url = info["formats"][0]["url"]
video_info = ydl.extract_info(video_url, download=False, process=False)
# Download video
video_info["title"] = info["title"]
video_info["subtitles"] = { "en": [ subs["en"] ] }
ydl.process_ie_result(video_info, download=True)
def download_show(ydl, url):
info = ydl.extract_info(url, download=False, process=False)
for ep in info["entries"]:
download_episode(ydl, ep["url"])
if __name__ == "__main__":
opts = {
'format': 'bestvideo+bestaudio',
'writesubtitles': True,
'subtitlesformat': 'srt',
'subtitleslangs': ['en'],
'outtmpl': '%(title)s.%(ext)s', # remove ID as it's "manifest" always
}
with youtube_dl.YoutubeDL(opts) as ydl:
download_show(ydl, url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment