views:

294

answers:

2

Hi,

I want to download you tube videos programatically (using Java). How can i convert you tube video link to a downloadable URL.

Browser plays youtube videos with following code.

I tried downloading from URL http://www.youtube.com/v/OdAE3cWlmHw but it is not returning video bytes.

Thanks Lalit

+1  A: 

Look at the dosens of extension for Firefox about downloading Flash video's. Downloadhelper and Flash Video Helper. If you look in the source you will find how to download the video. From what i remember is that it parses the HTML page for an id and session and use that in an url to download the video.

Similar question found only in C#. Watch the sources and you can recreate it in java C#: Downloading video from YouTube

PoweRoy
These tools saves played videos from browser's cache. I do not want to play video in browser. I want to create a java program which should be able to download video using URL.
lalit
That's incorrect. For downloadhelper: look at dhYoutubeProbe.js function YTProbe.prototype.handleDocument=function(document,window). There you can see it uses regex to extract video_id and token and use that "http://www.youtube.com/get_video?video_id="+videoId+""
PoweRoy
Yes we can create a link to download a youtube video. But still a problem.Here is the link to get a you tube videohttp://www.youtube.com/get_video?video_id=videoId VideoId is simple we can get it from url.But what about token. You tube provides a seperate token on each request. Means if i have requested a video from browser. In response my browser will get a token. By using that token i can make a downloadable link and download video using Java program.But what if i want to download using a program? From where i will get this token?
lalit
Download first the website and parse it, and use the token from there to start a download. Downloading and parsing the HTML page is quickly done.
PoweRoy
Now i can successfully create downloadable link for video (using token and vidoeId ). I can successfully download video by submitting this URL to browser. I have written a java program that download file from this URL using HttpURLConnection . It downloads file successfully on disk but problem is that i am not able to play this file. An error message is displaying 'This file contains no playable streams'
lalit
Have you got the correct codecs installed? try k-lite codec pack and play with media player classic
PoweRoy
A: 

this site has something.. for your need!

http://mashable.com/2009/02/13/youtube-toolbox/

www.ilavasam.com