Created
November 15, 2015 17:51
-
-
Save dattaz/d17fc77bc30ba98e11b1 to your computer and use it in GitHub Desktop.
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
#!/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