video.php类
<?php
/**
* 解析 视频信息 类
*
* 支持 优酷, 土豆 酷6 56 新浪 qq播客 乐视 乐视
**/
class class_video{
// 超时时间
var $timeout = 5;
/**
* 解析视频
*
* 1 参数 url 地址
*
* 返回值 数组 or false
**/
function parse( $url ) {
$arr = parse_url( $url );
if ( empty( $arr['host'] ) ) {
return false;
}
$host = strtolower( preg_replace( '/.*(?:$|\.)(\w+(?:\.(?:com|net|org|co|info)){0,1}\.[a-z]+)$/iU', '$1', $arr['host'] ) );
if ( $host == 'youku.com' ) {
return $this->youku( $url );
}
if ( $host == 'tudou.com' ) {
return $this->tudou( $url );
}
if ( $host == 'ku6.com' ) {
return $this->ku6( $url );
}
if ( $host == '56.com' ) {
return $this->_56( $url );
}
if ( $host == 'sina.com.cn' ) {
return $this->sina( $url );
}
if ( $host == 'qq.com' ) {
return $this->qq( $url );
}
if ( $host == 'letv.com' ) {
return $this->letv( $url );
}
if ( $host == 'sohu.com' ) {
return $this->sohu( $url );
}
return false;
}
/**
* 优酷的
*
* 1 参数 vid or url
*
* 返回值 false array
**/
function youku( $vid ) {
if ( !$vid ) {
return false;
}
if ( !preg_match( '/^[0-9a-z_-]+$/i', $vid ) ) {
if ( !preg_match( '/^http\:\/\/v\.youku\.com\/v_show\/id_([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/player\.youku\.com\/player\.php[0-9a-z\/_-]*\/sid\/([0-9a-z_-]+)/i', $vid, $match ) ) {
return false;
}
$vid = $match[1];
}
$url = 'http://v.youku.com/player/getPlayList/VideoIDS/' . $vid;
if ( !$json = $this->url( $url ) ) {
return false;
}
if ( !$json = @json_decode( $json, true ) ) {
return false;
}
if ( empty( $json['data'][0] ) ) {
return false;
}
$json = $json['data'][0];
$r['vid'] = $json['vidEncoded'];
$r['url'] = 'http://v.youku.com/v_show/id_'. $json['vidEncoded'] .'.html?f=http://www.lianyue.org/';
$r['swf'] = 'http://player.youku.com/player.php/sid/'. $json['vidEncoded'] .'/lianyue.swf';
$r['title'] = $json['title'];
$r['img']['large'] = $json['logo'];
$r['img']['small'] = str_replace( '.com/11', '.com/01', $json['logo'] );
$r['time'] = $json['seconds'];
$r['tag'] = $json['tags'];
return $r;
}
/**
* 土豆的
*
* 1 参数 vid or url
*
* 返回值 false array
**/
function tudou( $vid ) {
if ( !$vid ) {
return false;
}
if ( !preg_match( '/^[0-9a-z_-]+$/i', $vid ) ) {
if ( !preg_match( '/^http\:\/\/www\.tudou\.com\/programs\/view\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.tudou\.com\/v\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.tudou\.com\/(?:listplay|albumplay)\/[0-9a-z_-]+\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.tudou\.com\/(?:a|l)\/[0-9a-z_-]+\/.+iid\=(\d+)/i', $vid, $match ) ) {
return false;
}
$vid = $match[1];
}
$url = 'http://www.tudou.com/v/'. $vid .'/v.swf';
$this->url( $url, $header );
if( empty( $header['Location'] ) ) {
return false;
}
$parse = parse_url( $header['Location'] );
if ( empty( $parse['query'] ) ) {
return false;
}
$this->parse_str( $parse['query'], $arr );
if ( empty( $arr['snap_pic'] ) ) {
return false;
}
$r['vid'] = $arr['code'];
$r['url'] = 'http://www.tudou.com/programs/view/'. $arr['code'] .'/?FR=http://www.lianyue.org/';
$r['swf'] = 'http://www.tudou.com/v/'. $arr['code'] .'/lianyue.swf';
$r['title'] = $arr['title'];
$r['img']['large'] = $arr['snap_pic'];
$r['img']['small'] = str_replace( array( '/w.jpg', 'ykimg.com/11' ), array( '/p.jpg', 'ykimg.com/01' ), $arr['snap_pic'] );
$r['time'] = $arr['totalTime'] / 1000;
$r['tag'] = empty( $arr['tag'] ) || $arr['tag'] == 'null' ? array() : $this->array_unempty( explode( ',', $arr['tag'] ) );
return $r;
}
/**
* 酷 6 的
*
* 1 参数 vid or url
*
* 很老的视频某些 没大图
* 返回值 false array
**/
function ku6( $vid ) {
if ( !$vid ) {
return false;
}
if ( !preg_match( '/^[0-9a-z_-]+\.{0,2}$/i', $vid ) ) {
if ( !preg_match( '/^http\:\/\/v\.ku6\.com\/show\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/player\.ku6\.com\/refer\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/v\.ku6\.com\/special\/show_\d+\/([0-9a-z_-]+)/i', $vid, $match ) ) {
return false;
}
$vid = $match[1];
}
$vid = preg_replace( '/^([0-9a-z_-]+)\.*$/i', '$1..', $vid );
if ( !$json = $this->url( 'http://v.ku6.com/fetchVideo4Player/'. $vid .'.html' ) ) {
return false;
}
if ( !$json = @json_decode( $json, true ) ) {
return false;
}
if ( empty( $json['data']['picpath'] ) ) {
return false;
}
$json = $json['data'];
$json['vtime'] = explode( ',', $json['vtime'] );
$r['vid'] = $vid;
$r['url'] = 'http://v.ku6.com/show/'. $vid .'.h