?? xunlei.php
字號:
<?php
/*
秀影迅雷采集器2.0
208-10-6
*/
class xunlei extends DBModel {
public $server = null;
public $xml;
public $IO;
public function init(){
$this->IO = new Easy_Filesystem();
}
public function import(){
$i=0;
$stime = strtotime($this->_Response->getParams('stime'));
$etime = strtotime($this->_Response->getParams('etime'));
$save = intval($this->_Response->getParams('save'));
$this->num = intval($this->_Response->getParams('num'));
while($stime < $etime){ //循環(huán)導(dǎo)入影片資源
$stime = $stime+86400;
$this->IO->wfile(ROOT.'cache/xunlei.log', date('Y-m-d', $stime));
$file = 'http://u.xunlei.com/xml/'.date('Ymd', $stime).'.xml';
$filename = ROOT.'cache/xunlei/'.basename($file);
if (file_exists(ROOT.'cache/xunlei') === false){
mkdir(ROOT.'cache/xunlei', 0755);
}
if (file_exists($filename) === false){
$contents = file_get_contents($file);
if (file_exists($filename)===false && $contents){
$this->IO->wfile($filename, $contents);
}
}else{
$contents = file_get_contents($filename);
}
$this->parseMovie($contents);
$uri = preg_replace('&xunlei=(.*)/is', '&xunlei=', $_SERVER['REQUEST_URI']).'&stime='.date('Y-m-d', $stime).'&etime='.date('Y-m-d', $etime).'&save='.$save.'&num='.$this->num;
header("Location:".INSTALLDIR.'?mod=plugins&action=xunlei&uri='.base64_encode($uri));
exit;
}
return true;
}
/*解析影片資料*/
public function parseMovie(&$content){
$mov = new MovieModel();
$filter = array();
$filter['name'] = 'title';
$filter['big_pic'] = 'pic';
$filter['small_pic'] = 'otherpic';
$filter['actor'] = 'actor';
$filter['director'] = 'director';
$filter['description'] = 'content';
preg_match_all('/\<movie+\s+(.+?)\>(.+?)\<\/movie\>/is', $content, $temp);
if (is_array($temp[1])){
$i=0;
foreach ($temp[1] as $str){
$str = parse_str(str_replace(' ', '&', str_replace('"', '', $str)), $output);
//echo $str.'<br>';
foreach ($filter as $key=>$name){
$array[$name] =$this->parseName($temp[2][$i], $key);
}//end for
$category = null;
$category[] = $output['main_type'];
$category[] = $output['sub_type'];
$array['category'] = $this->changeCategory($category);
$array['player'] = 'xunlei';
if (preg_match('/([a-zA-Z]+)/is', $array['actor'])){
$array['area'] = '歐美';
}else{
$array['area'] = '港臺';
}
$urls = $this->parseUrl($temp[2][$i]); //從地址中獲取路徑與標(biāo)題
$array['url'] = $urls['url'];
$array['alt'] = $urls['name'];
$array['publish'] = '未知';
$array['sid'] = 1;
$array['look'] = 1;
$array['mkey'] = substr(md5($array['title']. $array['actor'].$array['director']),8,16);
$i++;
if ($output['change'] == 'update'){
$mov->delete($array['mkey']); //刪除已經(jīng)存在的影片
$mov->add($array); //修改已經(jīng)存在的
}else{
$movid = $mov->exists(array('mkey'=> $array['mkey']));
if ( $movid ){
$array['movid'] = $movid;
$mov->add($array, 'modify'); //修改已經(jīng)存在的
}else{
$mov->add($array);
}
}
$this->num = $this->num+1;
unset($array);
}//end for
}
}
public function parseName($content, $name){
$re = "/\<".$name."\>\<\!\[CDATA\[(.+?)\]\]\>\<\/".$name."\>/is";
preg_match($re, $content, $result);
return $result[1];
}
public function parseUrl($content){
preg_match('/\<file_list+\s(.+?)>(.+?)\<\/file_list\>/is', $content, $tmp);
$re = "/\<name\>\<\!\[CDATA\[(.+?)\]\]\>\<\/name\>/is";
preg_match_all($re, $tmp[2], $val);
$data['name'] = $val[1];
$re = "/\<params\>\<\!\[CDATA\[(.+?)\]\]\>\<\/params\>/is";
preg_match_all($re, $tmp[2], $val);
$data['url'] = $val[1];
return $data;
}
public function changeCategory($category){
$cate = new CategoryModel();
$main_type = array_shift($category);
$row = $cate->getRow("category like '{$main_type}%'");
if ($main_type){
if ($row['category']){
$mainid = $row['id'];
}else{
$mainid = $cate->Add(array('category' => $main_type, 'parentid'=>0));
}
$this->IO->wfile(ROOT.'cache/xunlei/category.log', $mainid."\n", 'a'); //寫入日志
}
foreach($category as $sub_type){
if ($sub_type){
$row = $cate->getRow("category like '{$sub_type}%'");
if ($row['category']){
$newType = $row['id'];
}else{
$newType = $cate->Add(array('category' => $sub_type, 'parentid'=>(int)$mainid));
}
$this->IO->wfile(ROOT.'cache/xunlei/category.log', $newType."\n", 'a'); //寫入日志
}
$cateid[] = $newType;
}
if (!$newType){
$cateid = $mainid;
}
return $cateid;
}
}?>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -