Last active
March 21, 2020 04:52
-
-
Save hclivess/5a4364d32195b4a460f10c07b645d6ec to your computer and use it in GitHub Desktop.
download all videos linked in links.txt, interface for youtube-dl
This file contains hidden or 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 subprocess | |
with open("links.txt") as infile: | |
lines = infile.readlines() | |
for line in lines: | |
filename = line.split("/")[-2] | |
command_line = f"youtube-dl {line} --verbose {filename}.mp4" | |
pipe = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE).stdout | |
output = pipe.read().decode() | |
pipe.close() | |
""" | |
import youtube_dl | |
retries = 1 | |
with open("links.txt") as infile: | |
lines = infile.readlines() | |
for line in lines: | |
for retry in range(retries): | |
try: | |
print(f"retry: {retry}") | |
#ydl_opts = {'outtmpl': filename, 'cookiefile': cookiefile} | |
ydl_opts = {} | |
ydl_opts['format'] = 'bestvideo[ext=mp4]+bestaudio' | |
with youtube_dl.YoutubeDL(ydl_opts) as ydl: | |
ydl.download([line]) | |
break | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment