因?yàn)閙accms自帶的采集采集起來很慢,而且很多資源站的采集接口不能對內(nèi)容排序,導(dǎo)致最舊的數(shù)據(jù)最后入庫。用java寫個(gè)采集程序,采集完入庫的時(shí)候發(fā)現(xiàn)不能一次性入庫多個(gè)數(shù)據(jù),導(dǎo)致入庫也很慢,所以就在入庫控制器寫了個(gè)方法批量入庫。
網(wǎng)站建設(shè)、成都做網(wǎng)站,成都做網(wǎng)站公司-創(chuàng)新互聯(lián)已向成百上千家企業(yè)提供了,網(wǎng)站設(shè)計(jì),網(wǎng)站制作,網(wǎng)絡(luò)營銷等服務(wù)!設(shè)計(jì)與技術(shù)結(jié)合,多年網(wǎng)站推廣經(jīng)驗(yàn),合理的價(jià)格為您打造企業(yè)品質(zhì)網(wǎng)站。
public function foo()
{
$info = $this->_param;
if (!array_key_exists("vods", $info) || empty($info["vods"]))
{
echo json_encode(['code'=>2002,'msg'=>"vods is required"],JSON_UNESCAPED_UNICODE);
exit;
}
$vods = json_decode($info["vods"], true);
if (null == $vods)
{
echo json_encode(['code'=>2002,'msg'=>"the format of vods is incorrect"],JSON_UNESCAPED_UNICODE);
exit;
}
$inter = mac_interface_type();
$res = [];
foreach ($vods as $vod)
{
if(empty($vod['type_id'])) {
$vod['type_id'] = $inter['vodtype'][$vod['type_name']];
}
$data['data'][] = $vod;
}
$res[] = model('Collect')->vod_data([],$data,1);
echo json_encode($res,JSON_UNESCAPED_UNICODE);
}
有時(shí)候需要給其他程序全量下載視頻數(shù)據(jù),有個(gè)接口會(huì)很方便
// format: json返回json格式數(shù)據(jù);無或line或其他返回的數(shù)據(jù),是一行一條數(shù)據(jù),且每一行都是合法的json格式
public function bar()
{
// token暫時(shí)無用
$token = $this->_param['token'];
$format = $this->_param['format'] == "json" ? "json" : "line";
$suffix = $format == "json" ? ".json" : ".txt";
// category暫時(shí)無用
$category = $this->_param['category'];
if (empty($category)) {
$category = "";
}
else {
$temp = explode(",", $category);
$category = "";
foreach ($temp as $k=>$v) {
if (is_numeric($v)) {
$category .= (($k==0 ? "" : ",") . $v);
}
}
}
$path = ROOT_PATH . "data".$suffix;
$url = request()->domain() . "/" . "data".$suffix;
if (is_file($path)) {
$mtime = (int)date("Ymd", filemtime($path));
$today = (int)date("Ymd", time());
if (filesize($path) > 0 && $mtime - $today == 0)
{
echo json_encode(["time" => $mtime, "url" => $url]);
exit;
}
}
$fp = new \SplFileObject($path, "a+b");
if ($fp->flock(LOCK_EX)) {
if ($fp->getSize() > 0) {
$fp->ftruncate(0);
$fp->fflush();
}
$count = Db::name('Vod')->count();
$i = 0;
$size = 2000;
$temp = $format == "json" ? array() : "";
while ($i<$count) {
$size = ($count-$i>=$size) ? $size : $count-$i;
$limit = $i . "," . $size;
// vod_class as class,
$list = Db::name('Vod')->field("vod_id as id,type_id as type,vod_name as name,vod_pic as pic,vod_play_url as playurl")->limit($limit)->select();
if ($format == "json") {
$temp = array_merge($temp,$list);
} else {
$temp = "";
foreach ($list as $k=>$v) {
if ($i >0 || ($i==0 && $k>0)) {
$temp .= "\r\n";
}
// JSON_UNESCAPED_UNICODE
$temp .= json_encode($v);
}
$fp->fwrite($temp);
$fp->fflush();
}
$i+=$size;
}
if ($format == "json")
{
// JSON_UNESCAPED_UNICODE
$fp->fwrite(json_encode($temp));
$count = count($temp);
$fp->fflush();
} else {
$fp->seek(PHP_INT_MAX);
$count = $fp->key() + 1;
}
$fp->flock(LOCK_UN);
$fp = null;
clearstatcache(true, $path);
echo json_encode(["time" => (int)date("Ymd", time()), "url" => $url, "count" => $count]);
exit;
}
echo json_encode(["time" => (int)date("Ymd", time()), "url" => "", "count" => 0]);
}