Archive for October, 2011


Dear reader,

in this article I will show you how to write an application for downloading videos from the online platform YouTube using any programming language like C# .Net, JavaScript or any other language. I think this topic is quite interesting because I implemented a download function in my YouTube Gadget and I did not find any helpful resources on the internet.

Let’s imagine following situation: You found

a cool video on YouTube, now you want to download it (for playing it on your PC, mobile phone or iPod…).
What we do have is the URL of the YouTube interface similar to “http://www.youtube.com/watch?v=M1wbceaOwfg” containing the swf-file that plays our video.
What we do not have is the URL of the video file our browser is loading. I used Firebug, a useful extension for developers, to get the video file.

Firebug - Getting the video URL

As you can see, I activated the “Netzwerk/Network” module and selected “Flash” contents. You notice that the request which is shown is the request for the video because of the “Content-Type” field of the response header (“Antwort-Header”) which is set to “video/x-flv”, the mimetype of flv-flash-videos. If you copy the requested URL to the address bar of our browser,  a download dialog will be shown and ask you to open or save “videoplayback”. Well, if this file is opened with Adobe Media Player or any other program being able to play flv-videos, you will see that you can watch the downloaded video.

I think this is clear, but more interesting is to automate this process and to download/convert the videos to a more common format. Which mobile phone or iPod can play flv-files? So the next step to do is to search the source code of the YouTube video page for our urls. And – to put it in a nutshell – it can be found in the flashvars of the embed-tag or the object (using Firefox, YouTube’s sourcecode is using an embed-tag while YouTube’s sourcecode for Internet Explorer is using an object-tag).
And this is the quite long code my sourcecode contains:

<embed type="application/x-shockwave-flash"     src="http://s.ytimg.com/yt/swfbin/watch_as3-vfl3Eh29q.swf"     width="640" id="movie_player" height="390"    flashvars="fexp=903104%2C907702&amp;url_encoded_fmt_stream_map=url%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v11.lscache4.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Cratebypass%25252Ccp%2526fexp%253D903104%25252C907702%2526itag%253D43%2526ip%253D87.0.0.0%2526signature%253D30417352A65E14163FB6746AE6C6A871517A5FC9.0C91E36B690A5C885AAE0B7F43FE564444C00AD0%2526sver%253D3%2526ratebypass%253Dyes%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dmedium%26fallback_host%3Dtc.v11.cache4.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26itag%3D43%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v21.lscache2.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D903104%25252C907702%2526algorithm%253Dthrottle-factor%2526itag%253D34%2526ip%253D87.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253DBC4BD5E7A48929985F533325AE046E5812B24D45.E599953DFB49361BD0CCDAE3A1FD06C4C7ED5A%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dmedium%26fallback_host%3Dtc.v21.cache2.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D34%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v22.lscache3.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Cratebypass%25252Ccp%2526fexp%253D903104%25252C907702%2526itag%253D18%2526ip%253D87.0.0.0%2526signature%253D81FDB64A4A19D55942C6C05CE4752A209C75C00D.D45F795019B8E8214EA20037660EF2B534C817F7%2526sver%253D3%2526ratebypass%253Dyes%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dmedium%26fallback_host%3Dtc.v22.cache3.c.youtube.com%26type%3Dvideo%252Fmp4%253B%2Bcodecs%253D%2522avc1.42001E%252C%2Bmp4a.40.2%2522%26itag%3D18%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v22.lscache3.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D903104%25252C907702%2526algorithm%253Dthrottle-factor%2526itag%253D5%2526ip%253D87.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253DAB1BAAB6AEB36AA5449436B3B70DAEAC6CF4A309.BFF1F8A5C9179CF25B9121968EA70A0A31DE0088%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dsmall%26fallback_host%3Dtc.v22.cache3.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D5&amp;enablecsi=1&amp;watermark=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswf%2Flogo-vfl_bP6ud.swf%2Chttp%3A%2F%2Fs.ytimg.com%2Fyt%2Fswf%2Fhdlogo-vfloR6wva.swf&amp;timestamp=1317576346&amp;plid=AASuVCYX1Hr0FlbH&amp;allow_embed=1&amp;watch_ajax_token=CzZGESebg7W8TR9XdtjYvm5lj4J8MTMxNzY2Mjc0NkAxMzE3NTc2MzQ2&amp;vq=auto&amp;showpopout=1&amp;autohide=2&amp;hl=en_US&amp;csi_page_type=watch5&amp;keywords=music%2Cyoutube%2Cgadget%2Cprogram%2Capp%2Capplication%2Csoftware%2Cwindows%2Cvista%2Cplayer%2Cplaylists%2Clisten%2Csidebar%2Cdesktop%2Cwidgets%2Centertainment%2Ccomputer&amp;cr=DE&amp;rvs=view_count%3D407%26author%3DRoboFan1406%26length_seconds%3D%2528104%252C%2529%26id%3D8q9RJ1wZQ5E%26title%3DLord%2Bof%2Bthe%2BRings%2B-%2BLord%2Bof%2Bthe%2BRings%2B-%2BShire%2BMusic%2Cview_count%3D162%26author%3DRoboFan1406%26length_seconds%3D%2528168%252C%2529%26id%3DyXnxYgUA2IA%26title%3DClimbing%2BNXT%2Cview_count%3D288%26author%3DRoboFan1406%26length_seconds%3D%2528109%252C%2529%26id%3DTRtIuqiBh50%26title%3DLEGO%2BMindstorms%2BNXT%2BGabelstapler%2Cview_count%3D4318143%26author%3DElektraRecords%26length_seconds%3D%2528257%252C%2529%26id%3Dfwr1hm_oBxE%26title%3DBruno%2BMars%2B-%2BIt%2BWill%2BRain%2B%255BNew%2BMusic%255D%2Cview_count%3D2724048%26author%3DkellyclarksonVEVO%26length_seconds%3D%2528235%252C%2529%26id%3D0C_oNMH0GTk%26title%3DKelly%2BClarkson%2B-%2BMr.%2BKnow%2BIt%2BAll%2Cview_count%3D2980984%26author%3DSMTOWN%26length_seconds%3D%2528203%252C%2529%26id%3DGvTaLTTanJc%26title%3DSuper%2BJunior%2B%25EC%258A%2588%25ED%258D%25BC%25EC%25A3%25BC%25EB%258B%2588%25EC%2596%25B4_A-CHA_Music%2BVideo%2Cview_count%3D1815682%26author%3DYourfavoritemartian%26length_seconds%3D%2528209%252C%2529%26id%3DTUmJDVRDRTQ%26title%3DWHIP%2BYO%2BKIDS%2Bfeaturing%2BNice%2BPeter%2Cview_count%3D953666%26author%3Drecklessswaggg%26length_seconds%3D%2528241%252C%2529%26id%3DPQocCi6j_mk%26title%3DHOW%2BTO%2BLOVE%2B%2528REMIX%2529%2B-%2BJUSTIN%2BBIEBER&amp;endscreen_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fendscreen-vflNhEga_.swf&amp;fmt_list=43%2F320x240%2F99%2F0%2F0%2C34%2F320x240%2F9%2F0%2F115%2C18%2F320x240%2F9%2F0%2F115%2C5%2F320x240%2F7%2F0%2F0&amp;referrer=None&amp;user_gender=m&amp;logwatch=1&amp;length_seconds=25&amp;sendtmp=1&amp;enablejsapi=1&amp;sk=764YjHpjrC6O1ctvYaH35ppV7Bd9b6mnR&amp;theme=dark&amp;t=vjVQa1PpcFM-sb-PCui5mX1jKwIXdE1yWObSxWPQFp8%3D&amp;video_id=M1wbceaOwfg&amp;p_w=P-KpDhgwPVs&amp;tk=SVN8E4f4bLdCNRlCrLgJIJlnzby7tCDb5dJjT08JFAX6-DLCnnC5rQ%3D%3D&amp;user_age=33"     allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000">

To make our flashvars more readable and accessible I decrypted the html-entities: (The following only shows the decoded flash parameters/flashvars, the other code is not too interesting.)

fexp=903104%2C907702
&url_encoded_fmt_stream_map=url%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v11.lscache4.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Cratebypass%25252Ccp%2526fexp%253D903104%25252C907702%2526itag%253D43%2526ip%253D87.0.0.0%2526signature%253D30417352A65E14163FB6746AE6C6A871517A5FC9.0C91E36B690A5C885AAE0B7F43FE564444C00AD0%2526sver%253D3%2526ratebypass%253Dyes%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dmedium%26fallback_host%3Dtc.v11.cache4.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26itag%3D43%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v21.lscache2.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D903104%25252C907702%2526algorithm%253Dthrottle-factor%2526itag%253D34%2526ip%253D87.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253DBC4BD5E7A48929985F533325AE046E5812B24D45.E599953DFB49361BD0CCDAE3A1FD06C4C7ED5A%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dmedium%26fallback_host%3Dtc.v21.cache2.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D34%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v22.lscache3.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Cratebypass%25252Ccp%2526fexp%253D903104%25252C907702%2526itag%253D18%2526ip%253D87.0.0.0%2526signature%253D81FDB64A4A19D55942C6C05CE4752A209C75C00D.D45F795019B8E8214EA20037660EF2B534C817F7%2526sver%253D3%2526ratebypass%253Dyes%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dmedium%26fallback_host%3Dtc.v22.cache3.c.youtube.com%26type%3Dvideo%252Fmp4%253B%2Bcodecs%253D%2522avc1.42001E%252C%2Bmp4a.40.2%2522%26itag%3D18%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.fra02s03.v22.lscache3.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D903104%25252C907702%2526algorithm%253Dthrottle-factor%2526itag%253D5%2526ip%253D87.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253DAB1BAAB6AEB36AA5449436B3B70DAEAC6CF4A309.BFF1F8A5C9179CF25B9121968EA70A0A31DE0088%2526expire%253D1317600000%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%2526id%253D335c1b71e68ec1f8%26quality%3Dsmall%26fallback_host%3Dtc.v22.cache3.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D5
&enablecsi=1
&watermark=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswf%2Flogo-vfl_bP6ud.swf%2Chttp%3A%2F%2Fs.ytimg.com%2Fyt%2Fswf%2Fhdlogo-vfloR6wva.swf
&timestamp=1317576346
&plid=AASuVCYX1Hr0FlbH
&allow_embed=1
&watch_ajax_token=CzZGESebg7W8TR9XdtjYvm5lj4J8MTMxNzY2Mjc0NkAxMzE3NTc2MzQ2
&vq=auto
&showpopout=1
&autohide=2
&hl=en_US
&csi_page_type=watch5
&keywords=music%2Cyoutube%2Cgadget%2Cprogram%2Capp%2Capplication%2Csoftware%2Cwindows%2Cvista%2Cplayer%2Cplaylists%2Clisten%2Csidebar%2Cdesktop%2Cwidgets%2Centertainment%2Ccomputer
&cr=DE
&rvs=view_count%3D407%26author%3DRoboFan1406%26length_seconds%3D%2528104%252C%2529%26id%3D8q9RJ1wZQ5E%26title%3DLord%2Bof%2Bthe%2BRings%2B-%2BLord%2Bof%2Bthe%2BRings%2B-%2BShire%2BMusic%2Cview_count%3D162%26author%3DRoboFan1406%26length_seconds%3D%2528168%252C%2529%26id%3DyXnxYgUA2IA%26title%3DClimbing%2BNXT%2Cview_count%3D288%26author%3DRoboFan1406%26length_seconds%3D%2528109%252C%2529%26id%3DTRtIuqiBh50%26title%3DLEGO%2BMindstorms%2BNXT%2BGabelstapler%2Cview_count%3D4318143%26author%3DElektraRecords%26length_seconds%3D%2528257%252C%2529%26id%3Dfwr1hm_oBxE%26title%3DBruno%2BMars%2B-%2BIt%2BWill%2BRain%2B%255BNew%2BMusic%255D%2Cview_count%3D2724048%26author%3DkellyclarksonVEVO%26length_seconds%3D%2528235%252C%2529%26id%3D0C_oNMH0GTk%26title%3DKelly%2BClarkson%2B-%2BMr.%2BKnow%2BIt%2BAll%2Cview_count%3D2980984%26author%3DSMTOWN%26length_seconds%3D%2528203%252C%2529%26id%3DGvTaLTTanJc%26title%3DSuper%2BJunior%2B%25EC%258A%2588%25ED%258D%25BC%25EC%25A3%25BC%25EB%258B%2588%25EC%2596%25B4_A-CHA_Music%2BVideo%2Cview_count%3D1815682%26author%3DYourfavoritemartian%26length_seconds%3D%2528209%252C%2529%26id%3DTUmJDVRDRTQ%26title%3DWHIP%2BYO%2BKIDS%2Bfeaturing%2BNice%2BPeter%2Cview_count%3D953666%26author%3Drecklessswaggg%26length_seconds%3D%2528241%252C%2529%26id%3DPQocCi6j_mk%26title%3DHOW%2BTO%2BLOVE%2B%2528REMIX%2529%2B-%2BJUSTIN%2BBIEBER
&endscreen_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fendscreen-vflNhEga_.swf
&fmt_list=43%2F320x240%2F99%2F0%2F0%2C34%2F320x240%2F9%2F0%2F115%2C18%2F320x240%2F9%2F0%2F115%2C5%2F320x240%2F7%2F0%2F0
&referrer=None
&user_gender=m
&logwatch=1
&length_seconds=25
&sendtmp=1
&enablejsapi=1
&sk=764YjHpjrC6O1ctvYaH35ppV7Bd9b6mnR
&theme=dark
&t=vjVQa1PpcFM-sb-PCui5mX1jKwIXdE1yWObSxWPQFp8%3D
&video_id=M1wbceaOwfg
&p_w=P-KpDhgwPVs
&tk=SVN8E4f4bLdCNRlCrLgJIJlnzby7tCDb5dJjT08JFAX6-DLCnnC5rQ%3D%3D
&user_age=20

The information sent to the Shockwave flash video is pretty interesting. My gender and age… For us, the interesting parameter is “url_encoded_fmt_stream_map“. This parameter is URL-encoded, here it it decoded.

url=http%3A%2F%2Fo-o.preferred.fra02s03.v11.lscache4.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cratebypass%252Ccp%26fexp%3D903104%252C907702%26itag%3D43%26ip%3D87.0.0.0%26signature%3D30417352A65E14163FB6746AE6C6A871517A5FC9.0C91E36B690A5C885AAE0B7F43FE564444C00AD0%26sver%3D3%26ratebypass%3Dyes%26expire%3D1317600000%26key%3Dyt1%26ipbits%3D8%26cp%3DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%26id%3D335c1b71e68ec1f8&quality=medium&fallback_host=tc.v11.cache4.c.youtube.com&type=video%2Fwebm%3B+codecs%3D%22vp8.0%2C+vorbis%22&itag=43
,url=http%3A%2F%2Fo-o.preferred.fra02s03.v21.lscache2.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%252Ccp%26fexp%3D903104%252C907702%26algorithm%3Dthrottle-factor%26itag%3D34%26ip%3D87.0.0.0%26burst%3D40%26sver%3D3%26signature%3DBC4BD5E7A48929985F533325AE046E5812B24D45.E599953DFB49361BD0CCDAE3A1FD06C4C7ED5A%26expire%3D1317600000%26key%3Dyt1%26ipbits%3D8%26factor%3D1.25%26cp%3DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%26id%3D335c1b71e68ec1f8&quality=medium&fallback_host=tc.v21.cache2.c.youtube.com&type=video%2Fx-flv&itag=34
,url=http%3A%2F%2Fo-o.preferred.fra02s03.v22.lscache3.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cratebypass%252Ccp%26fexp%3D903104%252C907702%26itag%3D18%26ip%3D87.0.0.0%26signature%3D81FDB64A4A19D55942C6C05CE4752A209C75C00D.D45F795019B8E8214EA20037660EF2B534C817F7%26sver%3D3%26ratebypass%3Dyes%26expire%3D1317600000%26key%3Dyt1%26ipbits%3D8%26cp%3DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%26id%3D335c1b71e68ec1f8&quality=medium&fallback_host=tc.v22.cache3.c.youtube.com&type=video%2Fmp4%3B+codecs%3D%22avc1.42001E%2C+mp4a.40.2%22&itag=18
,url=http%3A%2F%2Fo-o.preferred.fra02s03.v22.lscache3.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%252Ccp%26fexp%3D903104%252C907702%26algorithm%3Dthrottle-factor%26itag%3D5%26ip%3D87.0.0.0%26burst%3D40%26sver%3D3%26signature%3DAB1BAAB6AEB36AA5449436B3B70DAEAC6CF4A309.BFF1F8A5C9179CF25B9121968EA70A0A31DE0088%26expire%3D1317600000%26key%3Dyt1%26ipbits%3D8%26factor%3D1.25%26cp%3DU0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4%26id%3D335c1b71e68ec1f8&quality=small&fallback_host=tc.v22.cache3.c.youtube.com&type=video%2Fx-flv&itag=5

Conspicious is that the parameter is not completely decoded, but the rest is very readable. All related parameter collections are separated by a comma, their parameters with values are separated by an “&”-character but the values are URL-encoded again – here is the completely decoded version:

url=http://o-o.preferred.fra02s03.v11.lscache4.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Ccp
&fexp=903104%2C907702
&itag=43
&ip=87.0.0.0
&signature=30417352A65E14163FB6746AE6C6A871517A5FC9.0C91E36B690A5C885AAE0B7F43FE564444C00AD0
&sver=3
&ratebypass=yes
&expire=1317600000
&key=yt1
&ipbits=8
&cp=U0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4
&id=335c1b71e68ec1f8
&quality=medium
&fallback_host=tc.v11.cache4.c.youtube.com
&type=video/webm;+codecs="vp8.0,+vorbis"
&itag=43

,url=http://o-o.preferred.fra02s03.v21.lscache2.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Ccp
&fexp=903104%2C907702
&algorithm=throttle-factor
&itag=34
&ip=87.0.0.0
&burst=40
&sver=3
&signature=BC4BD5E7A48929985F533325AE046E5812B24D45.E599953DFB49361BD0CCDAE3A1FD06C4C7ED5A
&expire=1317600000
&key=yt1
&ipbits=8
&factor=1.25
&cp=U0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4
&id=335c1b71e68ec1f8
&quality=medium
&fallback_host=tc.v21.cache2.c.youtube.com
&type=video/x-flv
&itag=34

,url=http://o-o.preferred.fra02s03.v22.lscache3.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Ccp
&fexp=903104%2C907702
&itag=18
&ip=87.0.0.0
&signature=81FDB64A4A19D55942C6C05CE4752A209C75C00D.D45F795019B8E8214EA20037660EF2B534C817F7
&sver=3
&ratebypass=yes
&expire=1317600000
&key=yt1
&ipbits=8
&cp=U0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4
&id=335c1b71e68ec1f8
&quality=medium
&fallback_host=tc.v22.cache3.c.youtube.com
&type=video/mp4;+codecs="avc1.42001E,+mp4a.40.2"
&itag=18

,url=http://o-o.preferred.fra02s03.v22.lscache3.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Ccp
&fexp=903104%2C907702
&algorithm=throttle-factor
&itag=5
&ip=87.0.0.0
&burst=40
&sver=3
&signature=AB1BAAB6AEB36AA5449436B3B70DAEAC6CF4A309.BFF1F8A5C9179CF25B9121968EA70A0A31DE0088
&expire=1317600000
&key=yt1
&ipbits=8
&factor=1.25
&cp=U0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4
&id=335c1b71e68ec1f8
&quality=small
&fallback_host=tc.v22.cache3.c.youtube.com
&type=video/x-flv
&itag=5

Now we have got our data. There are four possible downloads (withdrawable from the type-parameter):

  1. The first download is a WebM video (a video format developed by Google) with a medium quality.
  2. The second download is a flash video with medium quality.
  3. The third download is a mp4-video with medium quality.
  4. The fourth download is a flash video with small quality.

Please note that every whole paragraph displayed in the box above is one single video url, i. e. the download url for the first video type is:

http://o-o.preferred.fra02s03.v11.lscache4.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Ccp&fexp=903104%2C907702&itag=43&ip=87.0.0.0&signature=30417352A65E14163FB6746AE6C6A871517A5FC9.0C91E36B690A5C885AAE0B7F43FE564444C00AD0&sver=3&ratebypass=yes&expire=1317600000&key=yt1&ipbits=8&cp=U0hQTFZLTl9FSkNOMF9ORVJBOms0SXNQbnhxVEI4&id=335c1b71e68ec1f8&quality=medium&fallback_host=tc.v11.cache4.c.youtube.com&type=video/webm;+codecs="vp8.0,+vorbis"&itag=43

Now, to download this video, just download the file from this URL and you are done.

Note: It is not possible to demonstrate this function online because we need to send a request to YouTube first to retreive this URL. This is not possible because cross-domain-scripting (XSS) is not allowed by most common browsers.

In my YouTube Gadget I use the following code to download videos:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Video Downloader</title>
</head>
<body>
<h1>AJAX YouTube Video Downloader</h1>
<h2>Demo by <a href="http://robofan.de">robofan.de</a></h2>
<form onsubmit="javascript:DownloadFormats(document.getElementById('VideoURL').value); return false;">
<table cellspacing="3" border="0" cellpadding="0">
<tr><td>Video URL:</td><td><input type="text" id="VideoURL" style="width: 245px;" /></td></tr>
<tr><td>Video format:</td><td><select id="downloadformat" disabled="disabled" style="width: 250px;"><option>Enter the URL of a video first</option></select></td></tr>
<tr><td></td><td><input type="submit" value="Retreive video formats" id="downloadbutton" style="width: 250px;" /></td></tr>
</table>
</form>
<script type="text/javascript">
var Status=0;
function exactTags(text, start, end, number) //this function allows to retreive a string between to tags - example: 'tag("<tag>any text</tag>", "<tag>", "</tag>", 0);' returns "any text"
{
    var first=text.split(start);
    if(first.length > number+1)
    {
        var second=first[number+1];
        first=second.split(end);
        second=first[0];
        return second;
    }
    else
    {
        return "";
    }
}
function DownloadFormats(VideoURL)
{
    if(Status==0)
    {
        var FormatRequest = new ActiveXObject("Microsoft.XMLHTTP");
        FormatRequest.open("GET", VideoURL, true); //initialize request to retreive video URLs
        FormatRequest.onreadystatechange = function()
        {
            if(FormatRequest.readyState === 4)
            {
                if(FormatRequest.status === 200)
                {
                    document.getElementById("downloadformat").disabled=false;
                    document.getElementById("downloadformat").options.length=0;
                    document.getElementById("downloadbutton").value="Download/Show";
                    var DownloadData=decodeURIComponent(exactTags(exactTags(FormatRequest.responseText, '<param name="flashvars" value="', '"', 0), "url_encoded_fmt_stream_map=", "&", 0)).split(",");
                    for(i=0; i < DownloadData.length; i++)
                    {
                        if(decodeURIComponent(exactTags(DownloadData[i], "type=", "&", 0)).split(";")[0]!="video/webm") //If a video is not a Google WebM video
                        {
                            document.getElementById("downloadformat").options[document.getElementById("downloadformat").options.length]=new Option(decodeURIComponent(exactTags(DownloadData[i], "type=", "&", 0)).split(";")[0]+" ("+decodeURIComponent(exactTags(DownloadData[i], "quality=", "&", 0))+")", decodeURIComponent(exactTags(DownloadData[i], "url=", "&", 0))); //Annex the URL to a select-list
                           �
                        }
                    }
                    Status=1;
                }
            }
        }
        FormatRequest.send(null); //Send the request
    }
    else
    {
        window.open(document.getElementById("downloadformat").value);
        Status=0;
        document.getElementById("downloadbutton").value="Retreive video formats";
        document.getElementById("downloadformat").options.length=0;
        document.getElementById("downloadformat").options[0]=new Option("Select a video first");
        document.getElementById("downloadformat").disabled=true;
    }
}
</script>
This is a downloader for YouTube videos. Originally it was programmed for <a href="http://youtube.com">youtube-gadget.com</a>.
<p>Please note that you may - depending on your location - violate laws by downloading videos which are protected by copyright.<br/>The author does not take over responsibility for any kind of abuse of this function or these terms.</p>
</body>
</html>

This works fine for downloading any video except those which are not available in Germany. To use this function in your Internet Explorer (it will not work with other browsers) you can download the document here. (Right click -> Save as…) Please be aware that the document has to be stored in your local file system because otherwise cross domain requests to YouTube are not allowed and it will not work. For the same reason you should allow blocked running scripts or ActiveX controls.

After downloading a video you can several conversion tools to convert the videos to any format.

Thank you for reading this long article, I hope I could inspire you. Please comment.

Best Regards
Birk

Please note that you may – depending on your location – violate laws by downloading videos which are protected by copyright.
The author does not take over responsibility for any kind of abuse of this function or these terms.

My gadgets on gallery.live.com

My gadgets

Yesterday I was very shocked when I saw that Microsoft retired “gallery.live.com“. It has always been a suitable platform for submitting my gadgets which got more than 380,000 downloads (the rest of the counted 54,000 downloads came from a similar German Microsoft platform – apps.msn.de – which is luckily not offline – but new contents cannot be submitted either). Another point is that my “Gallery Gadget”, which searched for gadgets on the site, does not work anymore, users are now redirected to this page.
The page that is shown instead of the gadget platform shows following message:

The Windows Live Gallery has been retired. In order to focus support on the much richer set of opportunities available for the newest version of Windows, Microsoft is no longer supporting development or uploading of new Gadgets. However, some of the most popular and highest-rated gadgets are still available on the Gadgets page of the Windows Personalization Gallery.

With Windows Developer Preview, developers can create rich app experiences where customers focus on their important tasks. Apps are at the center of the Windows Developer Preview experience and are alive with activity and vibrant content. Users immerse themselves in your full-screen app while Windows gracefully gets out of the way.

Windows Developer Preview allows you to leverage your existing skills and code assets so you can create great experiences for your customers. Gadget and web developers can now use their HTML5 and CSS3 skills to build native Windows apps. .NET Developers can use XAML, C#, and Visual Basic to build beautiful Metro-style apps. Game developers can use the power of DirectX 11.1 to build amazing, immersive gaming experiences. Driver developers benefit from increased productivity with the new, integrated Visual Studio development environment.

(Source: gallery.live.com – October 1, 2011)

Note the third paragraph! Windows Vista and Windows 7 are both still available at the markets and they do not support gadgets anymore while XP is still supported?! Therefore I can now build metro apps for an operating system which has not even reached beta status.
Unfortunately I am not a big fan of the new metro style, I think metro style is more regress than progress. I do not want to use a computer which is not distinguishable from a mobile phone.

UPDATE (January 5, 2012):

If you are searching the gadgets which were available in the gadget gallery, you will find them all at gallery-live.com. Note the difference of the domain name, the new site contains a minus (“-”) which replaces the dot (“.”) in gallery.live.com. This service is operated by myself and not by Microsoft.