萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> PHP抓取、分析國內視頻網站的視頻信息工具類

PHP抓取、分析國內視頻網站的視頻信息工具類

 VideoUrlParser是一款基於PHP根據視頻URL抓取視頻信息的工具,支持優酷、土豆、酷六、56、樂視、搜狐、騰訊、新浪。

使用方法:   代碼如下: require_once "VideoUrlParser.class.php"; $url = "http://v.youku.com/v_show/id_XMjkwMzc0Njg4.html"; $info = VedioUrlParser::parse($url); echo $info; 說明:調用該工具php文件VideoUrlParser.class.php,$url變量後面的字符串為視頻頁的地址,然後使用echo輸出變量$info。 附:info含有的幾個值,分別是img(用於視頻縮略圖),title(視頻標題),url(地址),swf(視頻swf播放地址)。我只用到了img和swf地址。具體的可以根據自己的需要進行調整。     VideoUrlParser類源碼:    代碼如下:<?php /**  * Video   *   * @package   * @version 1.2  * @copyright 2005-2011 HDJ.ME   * @author Dijia Huang <[email protected]>   * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}  *  * Usage  * require_once "VideoUrlParser.class.php";  * $urls[] = "http://v.youku.com/v_show/id_XMjI4MDM4NDc2.html";  * $urls[] = "http://www.tudou.com/playlist/p/l13087099.html";  * $urls[] = "http://www.tudou.com/programs/view/ufg-A3tlcxk/";  * $urls[] = "http://v.ku6.com/special/show_4926690/Klze2mhMeSK6g05X.html";  * $urls[] = "http://www.56.com/u68/v_NjI2NTkxMzc.html";  * $urls[] = "http://www.letv.com/ptv/vplay/1168109.html";  * $urls[] = "http://video.sina.com.cn/v/b/46909166-1290055681.html";  *  * foreach($urls as $url){  *     $info = VideoUrlParser::parse($url);  *     //var_dump($info);  *     echo "<a href='{$info['url']}' target='_new'>{$info['title']}</a>";  *     echo "<br />";  *     echo $info['object'];  *     echo "<br />";  * }  *  *  *  * //優酷  * http://v.youku.com/v_show/id_XMjU0NjY4OTEy.html  * <embed src="http://player.youku.com/player.php/sid/XMjU0NjY4OTEy/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>  *   * //酷六  * http://v.ku6.com/special/show_3917484/x0BMXAbgZdQS6FqN.html  * <embed src="http://player.ku6.com/refer/x0BMXAbgZdQS6FqN/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" allowfullscreen="true" type="application/x-shockwave-flash"></embed>  *   * //土豆  * http://www.tudou.com/playlist/p/a65929.html?iid=74905844  * <embed src="http://www.tudou.com/l/A_0urj-Geec/&iid=74905844/v.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="480" height="400"></embed>  *   * //56  * http://www.56.com/u98/v_NTkyODY2NTU.html  * <embed src="http://player.56.com/v_NTkyODY2NTU.swf"  type="application/x-shockwave-flash" width="480" height="405" allowNetworking="all" allowScriptAccess="always"></embed>  *   * //新浪播客  * http://video.sina.com.cn/v/b/46909166-1290055681.html  * <embed src="http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=46909166_1290055681_b0K1GHEwDWbK+l1l Hz2stqkP7KQNt6nki2O0u1ehIwZYQ0/XM5GdZNQH6SjQBtkEqDhAQJ42dfcn0Rs/s.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="ssss" allowFullScreen="true" allowScriptAccess="always" width="480" height="370"></embed>  *   * //樂視  * http://www.letv.com/ptv/vplay/1168109.html  * <embed src="http://i3.imgs.letv.com/player/swfPlayer.swf?id=1168109&host=app.letv.com&vstatus=1&AP=1&logoMask=0&isShowP2p=0&autoplay=true" quality="high" scale="NO_SCALE" wmode="opaque" bgcolor="#000000" width="480" height="388" name="FLV_player" align="middle" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">  */   class VideoUrlParser {     const USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko)         Chrome/8.0.552.224 Safari/534.10";     const CHECK_URL_VALID = "/(youku.com|tudou.com|ku6.com|56.com|letv.com|video.sina.com.cn|(my.)?tv.sohu.com|v.qq.com)/";       /**      * parse       *       * @param string $url       * @param mixed $createObject       * @static      * @access public      * @return void      */     static public function parse($url='', $createObject=true){         $lowerurl = strtolower($url);         preg_match(self::CHECK_URL_VALID, $lowerurl, $matches);         if(!$matches) return false;           switch($matches[1]){         case 'youku.com':             $data = self::_parseYouku($url);             break;         case 'tudou.com':             $data = self::_parseTudou($url);             break;         case 'ku6.com':             $data = self::_parseKu6($url);             break;         case '56.com':             $data = self::_parse56($url);             break;         case 'letv.com':             $data = self::_parseLetv($url);             break;         case 'video.sina.com.cn':             $data = self::_parseSina($url);             break;         case 'my.tv.sohu.com':         case 'tv.sohu.com':         case 'sohu.com':             $data = self::_parseSohu($url);             break;         case 'v.qq.com':             $data = self::_parseQq($url);             break;         default:             $data = false;         }           if($data && $createObject) $data['object'] = "<embed src="{$data['swf']}" quality="high" width="480" height="40 0" align="middle" allowNetworking="all" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>";         return $data;     }     /**      * 騰訊視頻       * http://v.qq.com/cover/o/o9tab7nuu0q3esh.ht
copyright © 萬盛學電腦網 all rights reserved