Saturday, September 6, 2008

How to download Youtube Videos using Javascript?

You can use Javascript and AJAX technologies to download Youtube videos on your web page that is all client based solution. I have outlined the steps to extract the values needed to form the URL to download the Youtube videos.

First we should know Youtube download URL summary:
Youtube videos can be downloaded from the URL http://youtube.com/get_video.php?=&l=&t=&sk=&fs=1. All we need are the values of video_id, l , t, and sk. My script extracts these values from Youtube's HTML page.

The summary of the script:
Download the source of the page of the URL http://in.youtube.com/watch?v=VDAGIFjt6m4
(
VDAGIFjt6m4 is the ID of a video). Look for a particular pattern in the source. Once the pattern is extracted convert it into JSON format. From the JSON data walk through and get the values of id, l, t, and sk.

More detailed algorithm.
1) Get the page source from Youtube using the public URL - http://in.youtube.com/watch?v=VDAGIFjt6m4
In the example VDAGIFjt6m4 is the ID. The ID can change depending upon your video.

2) The source will be entire page which has the Youtube video embedded we are only interested in the following HTML -
var swfArgs = {"BASE_YT_URL": "http://in.youtube.com/", "vq": null, "sourceid": "y", "video_id": "VDAGIFjt6m4", "l": 65, "sk": "mkKFIRWXheJgUGsaU6Bx2LsnWvZldVraC", "fmt_map": "6/720000/7/0/0", "t": "OEgsToPDskK0DEe01pPPKzJJ700ykmac", "hl": "en", "plid": "AARWNMbnD8zgFCZ0AAAAoAAYAAA", "sdetail": "p%3A/"};

3) Extract the interested line using the following Regular Expression "swfArgs(\\s*)=(\\s*)\\{(.*)\\}"

var ytPattern = "swfArgs(\\s*)=(\\s*)\\{(.*)\\}";
var re = new RegExp(ytPattern);
var matchVar = eval('({' + re.exec(strDoc) + '})');
Now from matchVar get the values like matchVar['video_id'] or matchVar['sk']

Once you the values substitute in
http://youtube.com/get_video.php?video_id=&l=&t=&sk=&fs=1

Disclaimer: If Youtube changes its page this script will not work. This is working as of Sept 6 2008.

Friday, August 22, 2008

New Gadget - News Flipper


News Flipper is a picture based news reader. You can flip the news like album covers. The user interface is based on Image Flow script. It has been modified to show the news articles. etc. It is developed as a Google gadget so that you can add this in your web page also.

To add it on your web page you can do one of the following
1) Go to Google Gadget's preview OR Add Gadget page.
2) Add to Google

3) Use the following script on your webpage-

Thursday, August 14, 2008

Movie trailers web page updated.

The movie trailers and Youtube mashup is gaining some traction in last few weeks. I have update the web page. I have also explained how the mash up works. Leave your suggestions and comemnts.

Saturday, August 9, 2008

Youtube Player shows "Olympics 2008"

It is very easy to change the initial search keyword in the Youtube Player. You can do this by changing the value of up_searchkey parameter in the script. I have recently changed that value to "Olympics 2008".
It is also possible to supply your own initial video. Check this. I will update about it later.

Check out some related links.
http://olympicsresults.blogspot.com
http://indiantrailers.blogspot.com

Thursday, June 26, 2008

Movie trailer gadget

I am planning to extend the feature set of the Movie Trailers gadget. Let me know what would you like to see in the gadget. Your suggestion and feedback will drive the next release. Also check the Youtube Player gadget.