Loading...

 

download videos from youtube (C#)

Categories: C# | Computer | Programing

I had a search in Google for the code(in C#) to download videos from youtube as flv file. But i could not find one. So i thought of writing one.

From the swfArgs from the source code get the value of fmt_url_map (Example video http://www.youtube.com/watch?v=ZzkresBOxnQ)

  "fmt_url_map": "18%7Chttp%3A%2F%2Fv18.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cburst%252Cfactor%26itag%3D18%26ipbits%3D0%26signature%3D594CDBBFBB9F091FEC9A27AB5BF4D6B82BB02A32.C7719537B15D9343F12FDF69D74B1D50AA4C07C4%26sver%3D3%26expire%3D1251460800%26key%3Dyt1%26factor%3D1.25%26burst%3D40%26id%3D67392b7ac04ec674%2C34%7Chttp%3A%2F%2Fv19.lscache3.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cburst%252Cfactor%26itag%3D34%26ipbits%3D0%26signature%3D65025436E8B5C24CE434758CBA3D0EEFEE54F9FE.33E6FC06E4AED75A3CE68AC92B7725094EE00A6E%26sver%3D3%26expire%3D1251460800%26key%3Dyt1%26factor%3D1.25%26burst%3D40%26id%3D67392b7ac04ec674%2C5%7Chttp%3A%2F%2Fv6.lscache3.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cburst%252Cfactor%26itag%3D5%26ipbits%3D0%26signature%3DD924DA3786E0B8187DBBC509D11A4B9E2856968B.0E6847032937C4FD9BF3F3607524CAADA6AE424D%26sver%3D3%26expire%3D1251460800%26key%3Dyt1%26factor%3D1.25%26burst%3D40%26id%3D67392b7ac04ec674"

search for http and from the last occurrence take rest of the string

http%3A%2F%2Fv6.lscache3.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cburst%252Cfactor%26itag

%3D5%26ipbits%3D0%26signature%3DD924DA3786E0B8187DBBC509D11A4B9E2856968B.0E6847032937C4FD9BF3F3607524CAADA6AE424D%26sver%3D3%26expire%3D1251460800%26key%3Dyt1%26factor%3D1.25%26burst%3D40%26id%3D67392b7ac04ec674

URL decode the line
http://v6.lscache3.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%252Cexpire%252Cip%252Cipbits%252Citag%252Cburst%252Cfactor&itag=5&ipbits=0&signature=D924DA3786E0B8187DBBC509D11A4B9E2856968B.0E6847032937C4FD9BF3F3607524CAADA6AE424D&sver=3&expire=1251460800&key=yt1&factor=1.25&burst=40&id=67392b7ac04ec674

Replace all %252 to %2
http://v6.lscache3.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cburst%2Cfactor&itag=5&ipbits=0&signature=D924DA3786E0B8187DBBC509D11A4B9E2856968B.0E6847032937C4FD9BF3F3607524CAADA6AE424D&sver=3&expire=1251460800&key=yt1&factor=1.25&burst=40&id=67392b7ac04ec674

thats all

The above was the latest Youtube download logic, updated the code too

 I got the details from the Opera user scripts and the scripts which can be used with firefox and Greasemonkey 

 It is simple  

 Here is the working example 

http://krishnan.co.in/codes/utube/default.aspx

 And here is the code tube.zip (19.97 kb)

 

You can make the changes with some more validations and regular expressions


 

Share It >>

Comments

Geekiest

February 13. 2008 00:18

Devidutta

the  code is not working
can you give me the  working code

Devidutta

Geekiest

February 15. 2008 02:42

Doich

It doesn't work !

Doich

Geekiest

April 6. 2008 02:28

krishnan

Updated the code. Now with error checking. Check it out

krishnan

Geekiest

October 15. 2008 05:54

ppoing

Error in Code

ppoing

Geekiest

October 15. 2008 07:29

Isaac

Hasta el momento el codigo funciona Laughing, gracias amigo

Isaac

Geekiest

October 16. 2008 07:50

krishnan

@ ppoing
What error mate ?

Have you tried any country specific you tube ? then you will have to change the

convert(string url) function

krishnan

Post Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678