In fact the process is basically: Call the fly donkey download api+js parsing + 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
Just a variety of software on the web and even Youku's own app does not provide high-definition video download features
And 1080P video itself is a paid feature for Youku
Just good DIY to conquer 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
I was hoping to find the developer Center for the Fly Donkey. _ (: З"∠) _ unfortunately rejected.
Just good intercept site Ajaxapi ...
This is the first to convert the page address into a Base64url conversion method can be used to test the development of the donkey's document
The function returns a string of JS code for further parsing.
Incidentally, this API frequent call will fail, probably the server itself will have to parse a return value ...
Cookiecontainer cookie = new Cookiecontainer (); string Getjs (String videourl) {string vUrl64 = Base64url (videourl); string Urltop = "Http://www.flvxz.com/?url=" +vurl64;//interview 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 very egg hurts ... 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 operation of this JS and we have to use the regular table to parse ...
In fact, my idea is to use regex parsing, combined with sgmlreader HTML formatting, and finally with Linq2xml crawl
is a lot of code-saving process.
If you want to study it carefully, analyze the DOM structure yourself =w=
The function returns a Youku instance that includes 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 Work It is the advantage of assuming that exception will voluntarily delete the download half of the file ...
If you want to support the continuation of the breakpoint, please write a lot of other text _ (: З"∠) _
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+ "complete Download");} 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 of the nausea and the number of parameters that are used on windows, it's just a good thing to give up ...
Suppose you know how to tune ffmpeg solve "multiple x264 stream merging and no quadratic coding" the puzzle Must Teach Me _ (: З"∠) _ Simply Masochistic
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 run 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