**Summarized:
**YouTube the world largest bideo braofcast company. People usually watch video under the web site or use the mashup to integrate into theirown blog. This article describes the way to deal with YouTube via C++ coding. I will show you how to handle YouTube API using Web Browser or using C++ to write a simple sample to demo how to get response from YouTube. Also I also tell you help to write a simple program to download YouTube video via HTTP connection client.
**YouTube APIs
**YouTube already provide lots of APIs which could help us to query video detail, get list by tag, list popular… All you have to do is open a url which like
[http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=XXXX_ID&tag=TakeThat](http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=XXXX_ID&tag=TakeThat) > >
As you see the URL it separate into three part:
-
“method=youtube.videos.list_by_tag”: it
is API name, whole API list is here. -
“dev_id=XXXX_ID”: Every API request need a developer ID which you can request here.
-
“&tag=TakeThat”: This API could help to figure out the list of specific tag. Oh my favorite band is “Take That” ^_^.
After you send the Http request via your browser, you would get the result XML as follow:
Yes, a XML based response which you could full handle it in any kinds of program you like.
**Download YouTube:
**Pick up any video from YouTube which like: http://youtube.com/watch?v=abK9WNFbKus&eurl=%2Findex. How to download it via Http connection? First I want to introduce a web site which can help you to transform your YouTube URL to a download-able address. 男丁格爾’s 脫殼玩 - FLV Video Parser Web 版 is a one of this web site.
Because any playback from YouTube need request a SK(I don’t know what is stand for). How to get the SK? You can paste a URL like http://youtube.com/watch?v=abK9WNFbKus&eurl=%2Findex, and you open the source code of this page (Use IE to right click and “View Source”). Search a strinbg as follow:
function writeMoviePlayer(player_div, force) { var v = "7"; if (force) v = "0"; > > var fo = new SWFObject("/player2.swf?hl=en&BASE_YT_URL=http://youtube.com/&video_id=1vjLC_gcftE&l=121&t=OEgsToPDskIwzbAyRDMe7MOVOjVzt-Qf&soff=1&sk=CxfMnY-qWhLIp4nOKIFWOgU", "movie_player", "450", "370", v, "#FFFFFF"); > > fo.addVariable("playnext", 0); fo.addVariable("hl", getQueryParamValue("hl")); fo.addParam("allowFullscreen", "true"); fo.addVariable("sourceid", "yw"); fo.addVariable("sdetail", "m%3Auser%2Crv%3AabK9WNFbKus"); player_written = fo.write(player_div); } > >
Use the “RED” string and connect with http://www.youtube.com/get_video? it should be http://www.youtube.com/get_video?video_id=1vjLC_gcftE&l=121&t=OEgsToPDskIwzbAyRDMe7MOVOjVzt-Qf&soff=1&sk=CxfMnY-qWhLIp4nOKIFWOgU it could download the video from YouTube directly. (The URL may invalid after a period time, please request it again.)
**Sample Program:
**Any handle of YouTube could via Http connection clien which IE/FireFox… CHttpClient is a very useful simple http client program which write by C++.
It has a clear GUI and useful connection API to get/post and request to Web Site via HTTP. I modify this application and change it to deal with YouTube.
Please download in
http://www.badongo.com/file/3563196
Any comment is welcome.