Пример #1
0
 public function getLinkContent()
 {
     require_once './ThinkPHP/Library/Vendor/Collection/phpQuery.php';
     $link = op_t(I('post.url'));
     $content = get_content_by_url($link);
     $charset = preg_match("/<meta.+?charset=[^\\w]?([-\\w]+)/i", $content, $temp) ? strtolower($temp[1]) : "utf-8";
     \phpQuery::$defaultCharset = $charset;
     \phpQuery::newDocument($content);
     $title = pq("meta[name='title']")->attr('content');
     if (empty($title)) {
         $title = pq("title")->html();
     }
     $title = iconv($charset, "UTF-8", $title);
     $keywords = pq("meta[name='keywords'],meta[name='Keywords']")->attr('content');
     $description = pq("meta[name='description'],meta[name='Description']")->attr('content');
     $url = parse_url($link);
     $img = pq("img")->eq(0)->attr('src');
     if (is_bool(strpos($img, 'http://'))) {
         $img = 'http://' . $url['host'] . $img;
     }
     $title = text($title);
     $description = text($description);
     $keywords = text($keywords);
     $return['title'] = $title;
     $return['img'] = $img;
     $return['description'] = empty($description) ? $title : $description;
     $return['keywords'] = empty($keywords) ? $title : $keywords;
     exit(json_encode($return));
 }
 public function getVideoInfo($link)
 {
     $return = S('video_info_' . md5($link));
     if (empty($return)) {
         require_once './ThinkPHP/Library/Vendor/Collection/phpQuery.php';
         preg_match("/(youku.com|ku6.com|sohu.com|sina.com.cn|qq.com|tudou.com|yinyuetai.com|iqiyi.com)/i", $link, $hosts);
         $host = $hosts[1];
         $content = get_content_by_url($link);
         if ('youku.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $flash_url = pq("#link2")->attr('value');
         } elseif ('ku6.com' == $host) {
             \phpQuery::$defaultCharset = GBK;
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $flash_url = pq(".ckl_input")->eq(0)->attr('value');
             $title = iconv("GBK", "UTF-8", $title);
         } elseif ('tudou.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             preg_match('/iid:(.*?)\\s+,icode/s', $content, $program);
             $programId = intval($program[1]);
             if (strpos($link, 'www.tudou.com/albumplay') !== false) {
                 preg_match("/albumplay\\/([\\w\\-\\.]+)[\\/|\\.]/", $link, $album);
                 $albumId = $album[1];
                 $flash_url = 'http://www.tudou.com/a/' . $albumId . '/&iid=' . $programId . '/v.swf';
             } elseif (strpos($link, 'www.tudou.com/programs') !== false) {
                 $flash_url = 'http://www.tudou.com/v/' . $programId . '/v.swf';
             } elseif (strpos($link, 'www.tudou.com/listplay') !== false) {
                 preg_match("/listplay\\/([\\w\\-\\.]+)\\//", $link, $list);
                 $listId = $list[1];
                 $flash_url = 'http://www.tudou.com/l/' . $listId . '/&iid=' . $programId . '/v.swf';
             }
         } elseif ('sohu.com' == $host) {
             \phpQuery::$defaultCharset = GBK;
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $title = iconv("GBK", "UTF-8", $title);
             $flash_url = pq("[property='og:videosrc']")->attr('content');
         } elseif ('qq.com' == $host) {
             $contentType = 'text/html;charset=gbk';
             \phpQuery::newDocument($content, $contentType);
             preg_match("/vid=(.*)/i", $link, $vid);
             $vid = $vid[1];
             $flash_url = 'http://static.video.qq.com/TPout.swf?vid=' . $vid . '&auto=0';
             $title = $title = pq("#" . $vid)->attr('title');
         } elseif ('sina.com.cn' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             preg_match("/swfOutsideUrl:\\'(.+?)\\'/i", $content, $flashvar);
             $flash_url = $flashvar[1];
         } elseif ('yinyuetai.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $flash_url = pq("[property='og:videosrc']")->attr('content');
         } elseif ('iqiyi.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $obj = pq("#videoArea")->find('div')->eq(0);
             $temp1 = $obj->attr('data-player-videoid');
             preg_match("/iqiyi.com\\/(.*).html/i", $link, $temp2);
             $temp2 = $temp2[1];
             $temp3 = $obj->attr('data-player-albumid');
             $temp4 = $obj->attr('data-player-tvid');
             $flash_url = 'http://player.video.qiyi.com/' . $temp1 . '/0/0/' . $temp2 . '.swf-albumId=' . $temp3 . '-tvId=' . $temp4;
         }
         $return['title'] = text($title);
         $return['flash_url'] = urldecode($flash_url);
         S('video_info_' . md5($link), $return, 60 * 60);
     }
     return $return;
 }
 public function getVideoInfo($link)
 {
     $return = S('video_info_' . md5($link));
     if (empty($return)) {
         require_once './ThinkPHP/Library/Vendor/Collection/phpQuery.php';
         preg_match("/(youku.com|ku6.com|sohu.com|sina.com.cn|qq.com|tudou.com|yinyuetai.com|iqiyi.com|bilibili.com)/i", $link, $hosts);
         $host = $hosts[1];
         $content = get_content_by_url($link);
         if ('youku.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $flash_url = pq("#link2")->attr('value');
             // 获取缩略图
             preg_match("/sid\\/(.*?)\\//", $flash_url, $id);
             // $json = get_content_by_url('http://v.youku.com/player/getPlayList/VideoIDS/' . $id[1]);
             $json = get_content_by_url('http://play.youku.com/play/get.json?vid=' . $id[1] . '&ct=10&ran=1951');
             $json = json_decode($json, true);
             $img_url = $json['data']['video']['logo'];
         } elseif ('ku6.com' == $host) {
             \phpQuery::$defaultCharset = GBK;
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $flash_url = pq(".ckl_input")->eq(0)->attr('value');
             $title = iconv("GBK", "UTF-8", $title);
             // 获取缩略图
             preg_match("/show\\/(.*?).html/", $link, $id);
             $json = get_content_by_url('http://v.ku6.com/fetch.htm?t=getVideo4Player&vid=' . $id[1]);
             $json = json_decode($json, true);
             $img_url = $json['data']['bigpicpath'];
         } elseif ('tudou.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             preg_match('/iid:(.*?)\\s+,icode/s', $content, $program);
             $programId = intval($program[1]);
             if (strpos($link, 'www.tudou.com/albumplay') !== false) {
                 preg_match("/albumplay\\/([\\w\\-\\.]+)[\\/|\\.]/", $link, $album);
                 $albumId = $album[1];
                 $flash_url = 'http://www.tudou.com/a/' . $albumId . '/&iid=' . $programId . '/v.swf';
             } elseif (strpos($link, 'www.tudou.com/programs') !== false) {
                 $flash_url = 'http://www.tudou.com/v/' . $programId . '/v.swf';
             } elseif (strpos($link, 'www.tudou.com/listplay') !== false) {
                 preg_match("/listplay\\/([\\w\\-\\.]+)\\//", $link, $list);
                 $listId = $list[1];
                 $flash_url = 'http://www.tudou.com/l/' . $listId . '/&iid=' . $programId . '/v.swf';
             }
             //获取缩略图
             $json = get_content_by_url('http://api.tudou.com/v6/video/info?app_key=myKey&format=json&itemCodes=' . $programId);
             $json = json_decode($json, true);
             $img_url = $json['results'][0]['bigPicUrl'];
         } elseif ('sohu.com' == $host) {
             \phpQuery::$defaultCharset = GBK;
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $title = iconv("GBK", "UTF-8", $title);
             $flash_url = pq("[property='og:videosrc']")->attr('content');
             // 获取缩略图
             preg_match("/com\\/(.*?)\\/v.swf/", $flash_url, $id);
             $json = get_content_by_url('http://hot.vrs.sohu.com/vrs_flash.action?vid=' . $id[1]);
             $json = json_decode($json, true);
             $img_url = $json['data']['coverImg'];
         } elseif ('qq.com' == $host) {
             $contentType = 'text/html;charset=gbk';
             \phpQuery::newDocument($content, $contentType);
             preg_match("/vid:\"(.*)\"/i", $content, $vid);
             $vid = $vid[1];
             $flash_url = 'http://static.video.qq.com/TPout.swf?vid=' . $vid . '&auto=0';
             $title = $title = pq("#" . $vid)->attr('title');
             // 获取缩略图
             $img_url = 'http://vpic.video.qq.com/d/' . $vid . '_ori_1.jpg';
         } elseif ('sina.com.cn' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             preg_match("/swfOutsideUrl:\\'(.+?)\\'/i", $content, $flashvar);
             $flash_url = $flashvar[1];
             //获取缩略图
             preg_match("/pic[\\s]*:[\\s]*[\"|\\']?[\\s]*([^'|\"]+)?/", $content, $mch1);
             $img_url = $mch1[1];
         } elseif ('yinyuetai.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $flash_url = pq("[property='og:videosrc']")->attr('content');
             //获取缩略图
             $img_url = pq("[property='og:image']")->attr('content');
         } elseif ('iqiyi.com' == $host) {
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             $obj = pq("#videoArea")->find('div')->eq(0);
             $temp1 = $obj->attr('data-player-videoid');
             preg_match("/iqiyi.com\\/(.*).html/i", $link, $temp2);
             $temp2 = $temp2[1];
             $temp3 = $obj->attr('data-player-albumid');
             $temp4 = $obj->attr('data-player-tvid');
             $flash_url = 'http://player.video.qiyi.com/' . $temp1 . '/0/0/' . $temp2 . '.swf-albumId=' . $temp3 . '-tvId=' . $temp4;
             //获取缩略图
             //$img_url = pq("[itemprop='thumbnailUrl']")->attr('content') ;
             //  $img_url = pq("[itemprop='image']")->attr('content') ;
             // 奇艺网有跨站过滤,使用默认图片
             $img_url = get_pic_src('/Public/images/iqiyi.jpg');
         } elseif ('bilibili.com' == $host) {
             $content = $this->gzdecode($content);
             \phpQuery::newDocument($content);
             $title = pq("title")->html();
             //获取缩略图
             $img_url = pq("[class='cover_image']")->attr('src');
             //获取视频地址
             $url_js = pq('#bofqi')->find('script')->eq(0)->html();
             preg_match("/(cid=\\w*)/", $url_js, $url_cid);
             preg_match("/aid=\\w*/", $url_js, $url_aid);
             $url_cid = substr($url_cid[0], strpos($url_cid[0], "=") + 1);
             $url_aid = substr($url_aid[0], strpos($url_aid[0], "=") + 1);
             $flash_url = "http://static.hdslb.com/play.swf" . "?cid=" . $url_cid . "&aid=" . $url_aid;
             //下载视频
             //                $link_bao = explode('bilibili.com',$link);
             //                $link_bi = $link_bao[0]."ibilibili.com".$link_bao[1];
             //                $content_bi = get_content_by_url($link_bi);
             //                \phpQuery::newDocument($content_bi);
             //                $obj_bi = pq("#firstLi")->find('a')->eq(3);
             //                $id_bi = $obj_bi->attr('onclick');
             //                preg_match("/[0-9]*/", $id_bi, $cid_bi);
         }
         $return['title'] = text($title);
         $return['flash_url'] = urldecode($flash_url);
         $return['img_url'] = urldecode($img_url);
         S('video_info_' . md5($link), $return, 60 * 60);
     }
     return $return;
 }