. NET Download Youku 1080P video

Source: Internet
Author: User
Tags flv file

In fact, the process is basically: Call fly Donkey Download api+js Resolution + file download + call Flvbind Merge Such a process _ (: З"∠) _

It seems that there is not much to explain. Well..

At first the demand was favorably cool to download some videos
But a variety of software on the web, even Youku's own app, does not offer the ability to download HD video.
And 1080P video itself is a paid feature for Youku
Had to DIY to solve the =w=

Some model classes

Class Youku {public string Url;public string title;public string quality;public int count;public list<youkuflvfile> Flvurls = new list<youkuflvfile> ();} Class Youkuflvfile {public string Filename;public string Fileurl;public string LocalFilename;}


Invoke API

Here originally wanted to find the Fly Donkey Developer Center to access the _ (: З"∠) _ unfortunately was rejected.
Had to intercept the website comes with Ajaxapi ...
This is the first to convert the page address into a Base64url conversion method can refer to the development of the donkey's documentation
The function returns a string of JS code for further parsing.

Incidentally, this API frequent call will fail the server itself will have to resolve a return value ...

Cookiecontainer cookie = new Cookiecontainer (); string Getjs (String videourl) {string vUrl64 = Base64url (videourl); string Urltop = "Http://www.flvxz.com/?url=" +vurl64;//access apihttpwebrequest req = (HttpWebRequest) webrequest.create ("https:/ /www.flvxz.com/getflv.php?url= "+vurl64); req. Referer = Urltop;req. Method = "Get"; req. Accept = "Application/javascript, */*;q=0.8"; req. Headers.add (Httprequestheader.acceptlanguage, "zh-hans-cn,zh-hans;q=0.7,ja;q=0.3"); req. useragent = "mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; trident/6.0) "; req. Host = "www.flvxz.com";//req. Cookiecontainer = cookie; HttpWebResponse resp = (httpwebresponse) req. GetResponse (); StreamReader sr = new StreamReader (resp. GetResponseStream (), Encoding.UTF8); string result = Sr. ReadToEnd (); resp. Close (); return result;} String base64url (string url) {url = URL. Replace ("://", ": # #"); string vUrlBase64 = Convert.tobase64string (Encoding.UTF8.GetBytes (URL)); vUrlBase64 = Vurlbase64.replace (' + ', '-'). Replace (' = ', ' _ '); return vUrlBase64;} 


JS parsing get FLV

This is a sore egg. The returned JS is a large section of the Eval statement consisting of multiple flvout (HTML, id) function calls
The original Flying Donkey page is the direct execution of this JS and we have to use regular expression parsing ...

In fact my train of thought is using regex parsing, combining sgmlreader to HTML formatting, and finally crawling with linq2xml
A series of procedures to save code.

If you want to study it carefully, analyze the DOM structure yourself =w=

function returns a Youku instance containing the file name of the child flv file and

Youku getyoukufiles (String youkuurl) {Youku Youku = new Youku (); Youku. URL = youkuurl;string js = Getjs (Youkuurl); Regex regex = new Regex (@ "flvout\" (' (. +?) ', ' (. +?) ' \) "); int idx = 0;foreach (Match m in regex. Matches (JS)) {string html = string. Format ("


Download file

Direct WebClient's work it's good that if it appears exception will automatically delete half of the files downloaded ...
If you want to support the continuation of the breakpoint, please write more words _ (: З"∠) _

void Download0 (Youku m) {var client = new WebClient (); if (m.flvurls.count>0) {string dir = Path.Combine (Downloaddir, m.t Itle); if (! Directory.Exists (dir)) {directory.createdirectory (dir);} Download foreach (var file in m.flvurls) {file. LocalFilename = Path.Combine (dir, file. FileName); if (! File.exists (file. LocalFilename)) {client. DownloadFile (file. FILEURL, file. LocalFilename); Console.WriteLine (file. filename+ "Download Complete");} else {Console.WriteLine (file. filename+ "file already exists");}}}


Merging FLV

Save time and effort directly with flvbind command line tools

Originally wanted to use FFmpeg direct turn into MP4, I have been crazy =w=
Because the problem with the nausea and parameters of the pipe used on Windows had to give up ...
If you know how to teach FFmpeg solve "multiple x264 stream merging and no quadratic coding" the problem must be taught me _ (: З"∠) _ Simply Abuse heart

void Combine0 (Youku m) {ProcessStartInfo PS = new ProcessStartInfo (@ "E:\Program files\ffmpeg-win64\bin\flvbind.exe"); Ps. Arguments = string. Join ("", new[]{m.title+ ". flv"}. Concat (M.flvurls.select (F=>f.localfilename)). Select (str=> "\" "+str+" \ "));p S. WorkingDirectory = Downloaddir;var p = Process.Start (PS);p. WaitForExit (); Console.WriteLine (m.title+ "Merge Complete");}

Finally, connect the above code to =w=

void Main () {String url = "Http://v.youku.com/v_show/id_XNzU4OTM0Njg0.html"; for (int t=0;t<5;t++) {var m = Getyoukufiles (URL), if (m.flvurls.count>0) {Download0 (M); File.exists (Path.Combine (Downloaddir, m.title+ ". flv"))) {Combine0 (M);}} else {Console.WriteLine ("Get failed ... Retry after 3 seconds "); Thread.Sleep (3000);}} String downloaddir = @ "D:\2014Cj";


The above code can be performed normally in win8x64. net4.5 LINQPad 4.48

Sgmlreader can be found in the CSDN download channel

Flvbind can search by itself is a very mini video processing tool

. NET Download Youku 1080P video

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.