PHP uses Youku Tudou's video address to obtain the swf player sharing address _ php instance

Source: Internet
Author: User
This article mainly introduces how to use Youku Tudou's video address to obtain the swf player sharing address, that is, to analyze Youku Tudou's video page address and obtain the corresponding swf player sharing address, if you need it, you can refer to the project to use temporary writing. To be improved:

The code is as follows:

/*
* Obtain the swf playback address of Youku and Tudou based on the (swf/html) address submitted by the user.
**/
Private function _ getSwf ($ url = ''){
If (isset ($ url )&&! Empty ($ url )){
Preg_match_all ('/http :\/\/(.*?)? \.(.*?)? \. Com \/(. *)/', $ url, $ types );
} Else {
Return false;
}
$ Type = $ types [2] [0];
$ Domain = $ types [1] [0];
$ Isswf = strpos ($ types [3] [0], 'v.swf ') === false? False: true;
$ Method = substr ($ types [3] [0], 0, 1 );

Switch ($ type ){
Case 'youku ':
If ($ domain = 'player '){
$ Swf = $ url;
} Else if ($ domain = 'V '){
Preg_match_all ('/http: \/v \. youku \. com \/v_show \/id _(.*)? \. Html/', $ url, $ url_array );
$ Swf = 'http: // player.youku.com/player.php/sid/'.str_replace ('/', '', $ url_array [1] [0]). '/v.swf ';
} Else {
$ Swf = $ url;
}
Break;
Case 'tuu ':
If ($ isswf ){
$ Swf = $ url;
} Else {
$ Method = 'p '? 'V': $ method;
Preg_match_all ('/http: \// www. tudou \. com \/(.*)? \/(.*)? /', $ Url, $ url_array );
$ Str_arr = explode ('/', $ url_array [1] [0]);
$ Count = count ($ str_arr );
If ($ count = 1 ){
$ Id = explode ('.', $ url_array [2] [0]) [0];
} Else if ($ count = 2 ){
$ Id = $ str_arr [1];
} Else if ($ count = 3 ){
$ Id = $ str_arr [2];
}
$ Swf = 'http: // www.tudou.com/'.w.method.'/'.mongoid.'/v.swf ';
}
Break;
Default:
$ Swf = $ url;
Break;
}
Return $ swf;
}

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.