Created
April 7, 2019 11:37
-
-
Save gaurav22verma/d1dd9cdb9527e1198244d66120afab7a to your computer and use it in GitHub Desktop.
A sample Python script to download audio from YouTube URL
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 pafy | |
import time | |
sample_URLs = ['wdPAIXBmcF0', 'FiiA9OSm5lc'] | |
for an_elt in sample_URLs: | |
URL = an_elt.strip() | |
try: | |
video = pafy.new(URL) | |
# Check that the duration of the video is less than 10 minutes | |
duration = video.duration.split(':') | |
if int(duration[0]) == 0 and int(duration[1]) <= 10: | |
bestaudio = video.getbestaudio() | |
Title = str(video.title) | |
bestaudio.download(filepath = './') | |
else: | |
continue | |
except: | |
print "Failed!" | |
time.sleep(21) | |
continue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment