去除土豆视频广告的PHP代码

index.php

<html>
<head>

	    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title>无广告播放</title>
</head>
<body>
    	<form action="result.php" method="POST">	
            <p>土豆视频播放页网址:请去掉网址最后面的.html</p>
            <input type="text" name="urlOfTuDou" style="height:51px;width:449px" />
			<p><input type="submit" name = "submitOfTuDou" value="提交" /></p><br /><br /><br />
        </form>
</body>
</html>


result.php

<?php
	
	include('noad.class.php');
	if($_POST['submitOfTuDou']){
		$url = $_POST['urlOfTuDou'];
		$reallyUrl = new noad();
		$content = $reallyUrl->tudou($url);
	}else if($_POST['submitOfYouKu']){
		$url = $_POST['submitOfYouKu'];
		$reallyUrl = new noad();
		$content = $reallyUrl->youku($url);
	}
	
	echo $content;

?>

noad.class.php

<?php

/*******************************
*土豆等视频网站,解析出无广告播放的地址的一个类
*需要传进来一个正常播放页面的地址
*注意:暂时只支持土豆、且需要把地址中的.html去掉之后进来
*
*
********************************/
	class noad{
	
		//土豆无广告
		public function tudou($url){
			if($url){
				$itemCodes = basename($url);
				$key = '1f3918053ff6bc04';//填写在土豆获得的key
				$api = 'http://api.tudou.com/v3/gw?method=item.info.get&appKey='.$key.'&format=json'.'&itemCodes='.$itemCodes;			
				$source = file_get_contents($api);
				$source = json_decode($source,true);
				$noadResult = $source['multiResult']['results']['0']['html5Url'];
				return $noadResult;
			}
		}
	}

?>

发表评论