PHP get Youku Video Real FLV file Address method _php Tips

Source: Internet
Author: User
Tags mixed flv file

This article illustrates how PHP obtains the Youku video true FLV file address. Share to everyone for your reference. The specific analysis is as follows:

There is a webmaster want me to help it do a Youku video site can automatically test the FLV real address, the following I sorted out the afternoon to solve the problem is very good, we can refer to.

This is to borrow force, just grab the content of the friend net, but quite handy, the code is as follows:

Copy Code code as follows:
<?php
$videourl = ' http://v.youku.com/v_show/id_XMjA5MjQ0OTQ0.html ';
function Get_content ($url, $data) {
if (Is_array ($data)) {
$data = Http_build_query ($data, ', ' & ');
}
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_postfields, $data);
$result = curl_exec ($ch);
return $result;
}
$str = get_content (' Http://share.pengyou.com/json.php?mod=usershare&act=geturlinfo ', array (' URL ' =>$ Videourl));
$str =json_decode ($STR);
Var_dump ($STR);
?>

This test is only SWF file is not the FLV file we want, and later reference to a webmaster to improve the wording, the core code is as follows:
Copy Code code as follows:
<?php
function fetch_youku_flv ($url) {
Preg_match ("#id_ (. *?). html# ", $url, $out);
$id = $out [1];
$content =get_curl_contents (' http://v.youku.com/player/getPlayList/VideoIDS/'. $id);
$data =json_decode ($content);
foreach ($data->data[0]->streamfileids as $k => $v) {
$sid =getsid ();
$fileid =getfileid ($v, $data->data[0]->seed);
$one = ($data->data[0]->segs-> $k);
if ($k = = ' flv ' | | | | $k = = ' mp4 ') return "http://f.youku.com/player/getflvpath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}? k={$one [0]->k}];
Continue
}
}
function get_curl_contents ($url, $second = 5) {
if (!function_exists (' Curl_init ')) die (' PHP.ini not open php_curl.dll ');
$c = Curl_init ();
curl_setopt ($c, Curlopt_url, $url);
$UserAgent =$_server[' http_user_agent '];
curl_setopt ($c, curlopt_useragent, $UserAgent);
curl_setopt ($c, curlopt_header,0);
curl_setopt ($c, Curlopt_timeout, $second);
curl_setopt ($c, Curlopt_returntransfer, true);
$cnt = curl_exec ($c);
$cnt =mb_check_encoding ($cnt, ' Utf-8 ')? Iconv (' GBK ', ' Utf-8//ignore ', $cnt): $cnt; Character encoding Conversion
Curl_close ($c);
return $cnt;
}
function GetSID () {
$sid = Time (). (Rand (0,9000) +10000);
return $sid;
}
function Getkey ($key 1, $key 2) {
$a = Hexdec ($key 1);
$b = $a ^ 0xa55aa5a5;
$b = Dechex ($b);
Return $key 2. $b;
}
function Getfileid ($fileId, $seed) {
$mixed = getmixstring ($seed);
$ids = Explode ("*", $fileId);
Unset ($ids [Count ($ids)-1]);
$realId = "";
for ($i =0; $i < count ($ids); + + $i) {
$idx = $ids [$i];
$realId. = substr ($mixed, $IDX, 1);
}
return $realId;
}
function getmixstring ($seed) {
$mixed = "";
$source = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/:._-1234567890";
$len = strlen ($source);
for ($i =0; $i < $len; + + $i) {
$seed = ($seed * 211 + 30031)% 65536;
$index = ($seed/65536 * strlen ($source));
$c = substr ($source, $index, 1);
$mixed. = $c;
$source = Str_replace ($c, "", $source);
}
return $mixed;
}
?>

Call the method, the code is as follows:
Copy Code code as follows:
$url = ' http://v.youku.com/v_show/id_XMzg2OTQ3MjQw.html ';
echo fetch_youku_flv ($url);

Access:

Copy Code code as follows:
Http://xiaomizhou.net/demo/flv.php?url=http://v.youku.com/v_show/id_XMzg2OTQ3MjQw.html

The result of the output is:

Copy Code code as follows:
Http://f.youku.com/player/getFlvPath/sid/138035737110468_00/st/flv/fileid/ 03000201004f97ef4a2e350467a09db266e872-5522-225f-dc45-40b4e1f9be49? K=c2a4327df2bb5a65261d40ea

This can be downloaded directly.

I hope this article will help you with your PHP program design.

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.