Created
November 16, 2020 23:20
-
-
Save pleonex/bbba5c093820c0a06a19df1c3f308612 to your computer and use it in GitHub Desktop.
Script to download videos and subtitles from Viki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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