首頁 >php教程 >php手册 >好东西又来了,通过优酷链接获取优酷真实视频地址

好东西又来了,通过优酷链接获取优酷真实视频地址

WBOY
WBOY原創
2016-06-07 11:43:501598瀏覽

好东西又来了,通过优酷链接获取优酷真实视频地址,需要的朋友可以拿去研究下,已测试过
更多技术文章请移步
http://www.dahuzhi.com
<?php <br /> <br> /*<br> 返回:<br> array<br>   'mp4' => string 'http://f.youku.com/player/getFlvPath/sid/138041779515547_00/st/mp4/fileid/03000804005241236C2C5300422C39EBED4FE4-2CCC-71BB-6AC3-59B4332828D7?K=48daa69002023a2a2828f4f1' (length=167)<br>   'flv' => string 'http://f.youku.com/player/getFlvPath/sid/138041779514451_00/st/flv/fileid/030002040052410FA52C5300422C39EBED4FE4-2CCC-71BB-6AC3-59B4332828D7?K=b9c1dfedde4eb5052828f4f1' (length=167)<br> */<br> <br> if(YoukuFlv::getYoukuFlv("http://v.youku.com/v_show/id_XNjEyOTE4NTEy_ev_1.html"))<br> {<br>     var_dump( YoukuFlv::result() );<br> }<br> else<br> {<br>     echo YoukuFlv::error();<br> }<br>  <br>  <br>  <br> /*<br> 获取优酷视频地址    <br> */<br> class YoukuFlv{<br>  <br>     static private $error   =   "";<br>     static private $result  =   array();<br>  <br>     static public function getYoukuFlv($url){<br>         //从url获取youkuid<br>         if(! $id    =   self::getYoukuId($url)){<br>             return false;<br>         }<br>         //获取youku视频详细信息<br>         $content    =   self::get_curl_contents( "http://v.youku.com/player/getPlayList/VideoIDS/".$id );<br>         $data   =   json_decode($content);<br>         if(!isset($data->data[0]->streamfileids)){<br>             self::$error    =   "Cannot find this video";<br>             return false;<br>         }<br>         foreach($data->data[0]->streamfileids AS $k=>$v){<br>             if($k == 'flv' || $k == 'mp4'){         <br>                 //sid<br>                 $sid=   self::getSid();<br>                 //fileid<br>                 $fileid =   self::getfileid($v,$data->data[0]->seed);<br>                 $one=($data->data[0]->segs->$k);<br>                 self::$result[$k]   = "http://f.youku.com/player/getFlvPath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}?K={$one[0]->k}";<br>             }<br>         }<br>         if(empty(self::$result)){<br>             self::$error    =   "THIS VIOD IS NOT IN MP4 OR FLV FORMAT";<br>             return false;<br>         }else{<br>             return true;<br>         }<br>     } <br>     static public function error(){<br>         return self::$error;<br>     }<br>  <br>     static public function result(){<br>         return self::$result;<br>     }<br>  <br>     static private function getYoukuId($url){       <br>         //url 不能为空<br>         if($url == "" || substr($url , 0 , 29) != "http://v.youku.com/v_show/id_"){<br>             self::$error    =   "URL IS ERROR";<br>             return false;<br>         }<br>         return substr($url , 29 , -5);      <br>     }<br>  <br>     static private function get_curl_contents($url, $second = 5){<br>         if(!function_exists('curl_init')) die('php.ini未开启php_curl.dll');<br>         $c = curl_init();<br>         curl_setopt($c,CURLOPT_URL,$url);<br>         $UserAgent=$_SERVER['HTTP_USER_AGENT'];<br>         curl_setopt($c,CURLOPT_USERAGENT,$UserAgent);<br>         curl_setopt($c,CURLOPT_HEADER,0);<br>         curl_setopt($c,CURLOPT_TIMEOUT,$second);<br>         curl_setopt($c,CURLOPT_RETURNTRANSFER, true);<br>         $cnt = curl_exec($c);<br>         curl_close($c);<br>         return $cnt;<br>     }<br>     static private function getSid() {<br>         $sid = time().(rand(0,9000)+10000);<br>         return $sid;<br>     }<br>     static private function getfileid($fileId,$seed) {<br>         $mixed = self::getMixString($seed);<br>         $ids = explode("*",$fileId);<br>         unset($ids[count($ids)-1]);<br>         $realId = "";<br>         for ($i=0;$i              $idx = $ids[$i];<br>             $realId .= substr($mixed,$idx,1);<br>         }<br>         return $realId;<br>     }<br>     static private function getMixString($seed) {<br>         $mixed = "";<br>         $source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\\:._-1234567890";<br>         $len = strlen($source);<br>         for($i=0;$i             $seed = ($seed * 211 + 30031) % 65536;<br>             $index = ($seed / 65536 * strlen($source));<br>             $c = substr($source,$index,1);<br>             $mixed .= $c;<br>             $source = str_replace($c, "",$source);<br>         }<br>         return $mixed;<br>     }<br> }<br>  <br>  <br>  <br> <br> ?>

AD:真正免费,域名+虚机+企业邮箱=0元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn