Last active
February 6, 2020 06:47
-
-
Save josenaves/6440058 to your computer and use it in GitHub Desktop.
Python code to grab videos from Youtube http://stackoverflow.com/questions/15512239/python-get-all-youtube-video-urls-of-a-channel
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 urllib, json | |
author = 'Youtube_Username' | |
foundAll = False | |
ind = 1 | |
videos = [] | |
while not foundAll: | |
inp = urllib.urlopen(r'http://gdata.youtube.com/feeds/api/videos?start-index={0}&max-results=50&alt=json&orderby=published&author={1}'.format( ind, author ) ) | |
try: | |
resp = json.load(inp) | |
inp.close() | |
returnedVideos = resp['feed']['entry'] | |
for video in returnedVideos: | |
videos.append( video ) | |
ind += 50 | |
print len( videos ) | |
if ( len( returnedVideos ) < 50 ): | |
foundAll = True | |
except: | |
#catch the case where the number of videos in the channel is a multiple of 50 | |
print "error" | |
foundAll = True | |
for video in videos: | |
print video['title'] # video title | |
print video['link'][0]['href'] #url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@josenaves, I have tried your code but it is giving me some error.
Error:
HTTPError: HTTP Error 404: Not Found