Getting details from Youtube URL

We can easily get many details from a youtube url using some of Python libraries. Here am going to show you how we can get
1)Video id
2)Video title
3)Author of video
4)Video thumbnails

We use Python’s urlparse, urllib and simplejson libraries to do this.

import urlparse
import urllib
import simplejson
url_data = urlparse.urlparse("http://www.youtube.com/watch?v=z_AbfPXTKms&NR=1")
video_id = urlparse.parse_qs(url_data.query)["v"][0]  # this is the video id
 
# from this url you will get all data you needed about video, by just replacing the video id
url = 'http://gdata.youtube.com/feeds/api/videos/%s?alt=json&v=2' % video_id 
json = simplejson.load(urllib.urlopen(url))

# this is the title of the video
title = json['entry']['title']['$t']  

# author of video               
author = json['entry']['author'][0]['name']['$t']
print "id:%s\nauthor:%s\ntitle:%s" % (id, author, title)

You will get thumbnails from this url: http://img.youtube.com/vi/video_id/image_id.jpg
image_id can be 0,1,2 or 3.

About these ads

One thought on “Getting details from Youtube URL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s