Skip to content

Instantly share code, notes, and snippets.

@dattaz
Created November 15, 2015 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dattaz/d17fc77bc30ba98e11b1 to your computer and use it in GitHub Desktop.
Save dattaz/d17fc77bc30ba98e11b1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import youtube_dl
import time
import sys
url = "https://www.youtube.com/watch?v=fiore9Z5iUg"
with youtube_dl.YoutubeDL({'outtmpl': 'video.mp4'}) as ydl:
attempts = 0
while attempts < 5:
try:
ydl.download([url])
break
except youtube_dl.utils.BlockedCopyright :
print "ignore this video beacause of copyright"
break
except:
e = sys.exc_info()[0]
attempts += 1
print "error : " + str(e)
if attempts == 5:
sys.exit("Error during getting video")
print "We will re-try to get this video in 10s"
time_to_wait = 60 * attempts
time.sleep(time_to_wait)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment