Created
November 13, 2013 01:47
-
-
Save yourtion/7442174 to your computer and use it in GitHub Desktop.
优酷、土豆、56获取视频截图和标题和播放swf代码
From http://blog.csdn.net/braverior/article/details/8986971
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class YoukuVideo | |
{ | |
var $url; | |
var $content; | |
var $videoswfstr; | |
var $playhtmlstr; | |
var $picurl; | |
var $err; | |
function show() | |
{ | |
echo $this->url; | |
//echo $this->content; | |
echo $this->videoswfstr; | |
echo $this->playhtmlstr; | |
echo $this->picurl; | |
} | |
function __construct($u) | |
{ | |
$this->url = $u; | |
$this->err=0; | |
$this->run(); | |
} | |
function getcontent() | |
{ | |
$co = @file_get_contents($this->url); | |
if(!$co) $err=true; | |
$this->content = $co; | |
} | |
function getsubstr($posstart,$posend) | |
{ | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(strlen($retstr )) return $retstr ; | |
else $err=1; | |
} | |
function youku_swf( ) //获取优酷的播放swf地址 | |
{ | |
$posstart = 'id="link2" value="'; | |
$posend = '" >'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(strstr($retstr,"swf"))$this->videoswfstr = $retstr; | |
else { | |
$this->err=1;$this->videoswfstr=""; | |
} | |
} | |
function youku_playhtml() //获取优酷的播发界面 | |
{ | |
$this->playhtmlstr = @sprintf('<embed src="%s" allowFullScreen="true" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>',$this->videoswfstr); | |
} | |
function youku_thumb()//获取优酷视频的截图(只能返回小图的地址) | |
{ | |
$posstart = "&screenshot="; | |
$posend = '" target="_blank"'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(!$retstr) $err=1; | |
$this->picurl = $retstr; | |
} | |
function youku_gettitle() | |
{ | |
$posstart = '<meta name="title" content="'; | |
$posend = '">'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(!$retstr) $err=1; | |
$this->title = $retstr; | |
} | |
function run() | |
{ | |
$this->getcontent(); | |
$this->youku_swf(); | |
$this->youku_playhtml(); | |
$this->youku_thumb(); | |
$this->youku_gettitle(); | |
//$this->show(); | |
} | |
} | |
class TuDouVideo | |
{ | |
var $url; | |
var $content; | |
var $videoswfstr; | |
var $playhtmlstr; | |
var $picurl; | |
var $err; | |
function __construct($u) | |
{ | |
$this->url = $u; | |
$this->err=0; | |
$this->run(); | |
} | |
function getcontent() | |
{ | |
$co = @file_get_contents($this->url); | |
if(!$co) $err=true; | |
$this->content = $co; | |
} | |
function getsubstr($posstart,$posend) | |
{ | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(strlen($retstr )) return $retstr ; | |
else $err=1; | |
} | |
function tudou_swf( ) //获取优酷的播放swf地址 | |
{ | |
$baseurl = "http://www.tudou.com/v/9jT9ScDxkP4/&resourceId=0_04_05_99/v.swf"; | |
$posstart = ",icode: '"; | |
$posend = "' "; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if($retstr)$this->videoswfstr = $retstr; | |
else { | |
$this->err=1;$this->videoswfstr=""; | |
} | |
} | |
function tudou_playhtml() //获取优酷的播发界面 | |
{ | |
$this->playhtmlstr = @sprintf('http://www.tudou.com/v/%s/&resourceId=0_04_05_99/v.swf',$this->videoswfstr); | |
} | |
function tudou_thumb()//获取优酷视频的截图(只能返回小图的地址) | |
{ | |
$posstart = ",pic: '"; | |
$posend = "' "; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(!$retstr) $err=1; | |
$this->picurl = $retstr; | |
} | |
function tudou_gettitle() | |
{ | |
$posstart = ",kw: '"; | |
$posend = "' "; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(!$retstr) $err=1; | |
$this->title = $retstr; | |
} | |
function run() | |
{ | |
$this->getcontent(); | |
$this->tudou_swf(); | |
$this->tudou_playhtml(); | |
$this->tudou_thumb(); | |
$this->tudou_gettitle(); | |
//$this->show(); | |
} | |
} | |
class WoLeVideo | |
{ | |
var $url; | |
var $content; | |
var $videoswfstr; | |
var $playhtmlstr; | |
var $picurl; | |
var $err; | |
function __construct($u) | |
{ | |
$this->url = $u; | |
$this->err=0; | |
$this->run(); | |
} | |
function getcontent() | |
{ | |
$co = @file_get_contents($this->url); | |
if(!$co) $err=true; | |
$this->content = $co; | |
} | |
function getsubstr($posstart,$posend) | |
{ | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(strlen($retstr )) return $retstr ; | |
else $err=1; | |
} | |
function wole_swf( ) //获取56的播放swf地址 | |
{ | |
$posstart = '"EnId":"'; | |
$posend = '"}'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(strlen($retstr) < 20 && strlen($retstr) > 0) | |
{ | |
$this->playhtmlstr = @sprintf('http://player.56.com/v_%s.swf',$retstr); | |
$this->videoswfstr = $this->playhtmlstr; | |
} | |
else { | |
$this->err=1;$this->videoswfstr=""; | |
} | |
} | |
function wole_playhtml() //获取优酷的播发界面 | |
{ | |
//$this->playhtmlstr = @sprintf('http://www.tudou.com/v/%s/&resourceId=0_04_05_99/v.swf',$this->videoswfstr); | |
} | |
function wole_thumb()//获取优酷视频的截图(只能返回小图的地址) | |
{ | |
$posstart = '"URL_URLid":"'; | |
$posend = '",'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr1 = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
$posstart = '"user_id":"'; | |
$posend = '",'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr2 = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
$posstart = '"URL_pURL":"'; | |
$posend = '",'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr3 = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
$posstart = '"URL_sURL":"'; | |
$posend = '",'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr4 = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
$posstart = '"img_host":"'; | |
$posend = '",'; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr5 = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
$this->picurl = @sprintf('http://%s/images/%s/%s/%si56olo56i56.com_%s.jpg',$retstr5,$retstr3,$retstr4,$retstr2,$retstr1); | |
} | |
function wole_gettitle() | |
{ | |
$posstart = "<title>"; | |
$posend = "</title>"; | |
$len1 = strpos($this->content,$posstart); | |
$len2 = strpos($this->content,$posend,$len1); | |
$retstr = @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart)); | |
if(!$retstr) $err=1; | |
$this->title = $retstr; | |
} | |
function run() | |
{ | |
$this->getcontent(); | |
$this->wole_swf(); | |
$this->wole_playhtml(); | |
$this->wole_thumb(); | |
$this->wole_gettitle(); | |
//$this->show(); | |
} | |
} | |
$test = new WoLeVideo("http://www.56.com/u49/v_OTE4NTY5OTA.html"); | |
//echo $test->err; | |
if($test->err) echo "无法解析此地址"; | |
else echo "<img src=".$test->picurl.">"; | |
echo $test->title; | |
echo $test->playhtmlstr; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment