Skip to content

Instantly share code, notes, and snippets.

@hclivess
Last active March 21, 2020 04:52
Show Gist options
  • Save hclivess/5a4364d32195b4a460f10c07b645d6ec to your computer and use it in GitHub Desktop.
Save hclivess/5a4364d32195b4a460f10c07b645d6ec to your computer and use it in GitHub Desktop.
download all videos linked in links.txt, interface for youtube-dl
"""
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