Browse Source

fix video filename

master
filesite 8 months ago
parent
commit
cd5ac01f6b
  1. 21
      themes/tajian/controller/FrontapiController.php

21
themes/tajian/controller/FrontapiController.php

@ -219,7 +219,7 @@ Class FrontApiController extends SiteController {
} }
//保存快捷方式 //保存快捷方式
protected function saveUrlShortCut($task_id, $task_url) { protected function saveUrlShortCut($video_id, $task_url) {
$data_dir = __DIR__ . '/../../../runtime/' . FSC::$app['config']['tajian']['data_dir']; $data_dir = __DIR__ . '/../../../runtime/' . FSC::$app['config']['tajian']['data_dir'];
if (!is_dir($data_dir)) { if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true); mkdir($data_dir, 0755, true);
@ -231,7 +231,7 @@ URL={$task_url}
eof; eof;
try { try {
$filepath = "{$data_dir}/{$task_id}.url"; $filepath = "{$data_dir}/{$video_id}.url";
return file_put_contents($filepath, $shortUrlContent); return file_put_contents($filepath, $shortUrlContent);
}catch(Exception $err) { }catch(Exception $err) {
return false; return false;
@ -239,7 +239,7 @@ eof;
} }
//保存描述文件:标题和图片 //保存描述文件:标题和图片
protected function saveDescriptionFiles($task_id, $task_data) { protected function saveDescriptionFiles($video_id, $task_data) {
$data_dir = __DIR__ . '/../../../runtime/' . FSC::$app['config']['tajian']['data_dir']; $data_dir = __DIR__ . '/../../../runtime/' . FSC::$app['config']['tajian']['data_dir'];
if (!is_dir($data_dir)) { if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true); mkdir($data_dir, 0755, true);
@ -249,18 +249,18 @@ eof;
try { try {
//保存标题 //保存标题
$filepath_title ="{$data_dir}/{$task_id}_title.txt"; $filepath_title ="{$data_dir}/{$video_id}_title.txt";
file_put_contents($filepath_title, $task_data['title']); file_put_contents($filepath_title, $task_data['title']);
//保存图片文件 //保存图片文件
if (!empty($task_data['cover_base64'])) { if (!empty($task_data['cover_base64'])) {
$filepath_cover ="{$data_dir}/{$task_id}.{$task_data['cover_type']}"; $filepath_cover ="{$data_dir}/{$video_id}.{$task_data['cover_type']}";
file_put_contents($filepath_cover, $task_data['cover_base64']); file_put_contents($filepath_cover, $task_data['cover_base64']);
$filepath_desc ="{$data_dir}/{$task_id}_cover.txt"; $filepath_desc ="{$data_dir}/{$video_id}_cover.txt";
file_put_contents($filepath_desc, "{$task_id}.{$task_data['cover_type']}"); file_put_contents($filepath_desc, "{$video_id}.{$task_data['cover_type']}");
}else if (!empty($task_data['cover'])) { }else if (!empty($task_data['cover'])) {
$filepath_desc ="{$data_dir}/{$task_id}_cover.txt"; $filepath_desc ="{$data_dir}/{$video_id}_cover.txt";
file_put_contents($filepath_desc, "{$task_data['cover']}"); file_put_contents($filepath_desc, "{$task_data['cover']}");
} }
}catch(Exception $err) { }catch(Exception $err) {
@ -308,8 +308,9 @@ eof;
$code = 0; $code = 0;
$err = '签名验证不通过!'; $err = '签名验证不通过!';
}else if (!empty($task_result['done'])) { //如果任务成功抓取到数据 }else if (!empty($task_result['done'])) { //如果任务成功抓取到数据
$saveUrlRes = $this->saveUrlShortCut($task_id, $task_result['url']); $video_id = $this->getVideoId($task_result['url']);
$saveDescRes = $this->saveDescriptionFiles($task_id, $task_result); $saveUrlRes = $this->saveUrlShortCut($video_id, $task_result['url']);
$saveDescRes = $this->saveDescriptionFiles($video_id, $task_result);
if (!$saveUrlRes) { if (!$saveUrlRes) {
$code = 0; $code = 0;
$err = '网址快捷方式文件保存失败!'; $err = '网址快捷方式文件保存失败!';

Loading…
Cancel
Save