<?php
//include_once 'curl.php';
class my_vod{
private $t; //私有成员,输出的视频地址,是数组,在使用前必须调用get_html_vod 或者get_db_vod来初始化它
public $url; //公用成员,要采集的网址;
private function get_html_vod(){
$html=file_get_contents($this->url);
$html = iconv("gbk", "UTF-8", $html);
$pat = "/<a(.*?)href=\"(.*?)\"(.*?)>(.*?MP4)<\/a>/i";
//$pat = "/<a(.*?)href=\"(.*?)\"(.*?)>(.*?".$w.")<\/a>/i";
preg_match_all($pat, $html, $tmp);
$this->t=$tmp[2];
}
private function get_db_vod(){
include 'conn.php';
$row=mysql_query('select url from vod_zp order by id desc',$con);
while ($arr=mysql_fetch_array($row)){
$this->t[]=$arr[0];
}
}
private function insert_db($t){
include 'conn.php';
$t1=urlencode($t);
$qry=mysql_query("select url from vod_zp where url='$t'",$con);
if (mysql_num_rows($qry)<1){
mysql_query("insert into vod_zp(url,urlen,createtime) values('$t','$t1',now())",$con);
}
}
function download_all(){
$this->get_html_vod(); //初始化成员T的内容;
$ssh_name=date("His").".ssh";
$ssh_path="/usr/local/nginx/html/file/".$ssh_name;
$f=fopen($ssh_path,"w");
fwrite ($f,"#!/bin/sh");
fwrite ($f,"\n");
for ($i=0;$i<sizeof($this->t);$i++) {
$t=$this->t[$i];
//$t=str_replace('cn2.dvd9.me','192.168.1.221',$t);
if (!file_exists("/usr/local/nginx/html/file/".md5($t).".MP4")) {
fwrite ($f,"wget '$t' -O /usr/local/nginx/html/file/".md5($t).".MP4");
fwrite ($f,"\n");
}
}
fwrite($f,"rm -f ".$ssh_path);
fclose($f);
// exec("chmod 711 $ssh_path");
// exec($ssh_path);
}
function echo_vod($sleep=1,$db=1){
if ($db===1){
$this->get_db_vod();
}else{
$this->get_html_vod();
}
$i=0;
for ($i=0;$i<sizeof($this->t);$i++){
$i=$i++;
$ar=$this->t[$i];
$this->insert_db($ar);
echo $i.":".$ar;
if ($sleep===1){
$md5file="/file/".md5($ar).".MP4";
echo "<a href=http://$_SERVER[HTTP_HOST]$md5file>播放</a>";
}else{
echo "<a href=\"$ar\">播放</a>";
}
echo " || ";
echo "<a href=http://$_SERVER[HTTP_HOST]/tools/curl.php?url=$ar>缓存到服务器</a>";
echo "<br>";
}
}
}
$obj=new my_vod();
$obj->url="http://free.yoyokiss.com/vod/";
if ($_GET[db]){
if ($_GET[sleep]){
$obj->echo_vod(1,1);
}else{
$obj->echo_vod(0,1);
}
}else{
if ($_GET[sleep]){
$obj->echo_vod(1,0);
}else if ($_GET[c]){
$obj->download_all();
}else{
$obj->echo_vod(0,0);
}
}
?>
preferences:
36.92 ms | 402 KiB | 5 Q