From 833fe442815435fefe208a741cbee89b33ed1673 Mon Sep 17 00:00:00 2001 From: JULM-COMPUTER Date: Fri, 18 Apr 2025 09:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=B7=B2=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8D=E8=BF=9B=E8=A1=8C=E4=B8=8B=E8=BD=BD=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E8=AF=B7=E5=88=A0=E9=99=A4download=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/Zm.php | 52 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/app/command/Zm.php b/app/command/Zm.php index eb90401..6358161 100644 --- a/app/command/Zm.php +++ b/app/command/Zm.php @@ -74,7 +74,7 @@ class Zm extends Command $this->savetxt($introduce,$curr_item['introduce']); $cover = $curr_item['cover']; - $this->download($cover,$c); + $this->download($cover,$c,basename($cover)); $cover_name = basename($cover); $cover_path = "{$c}/{$cover_name}-下载地址.txt"; @@ -84,20 +84,36 @@ class Zm extends Command $class_path = $c . '/' . $class['title']; is_dir($class_path) || mkdir($class_path,0755,true); $class_details = $this->getClassDetails($class['id']); + if($class_details == false){ + dump('课程未授权,跳过下载',$class['title']); + break; + } dump($class_path,$class_details); $class_id = $class_details['data']['classSection']['id']; if(!empty($class_details['data']['classSection']['video'])){ - $this->download($class_details['data']['classSection']['video'],$class_path); + $file_name = urldecode(basename($class_details['data']['classSection']['video'])); + $downloadurl = $class_path . '/' . $file_name . '-下载地址.txt'; + $this->savetxt($downloadurl,$class_details['data']['classSection']['video']); + $this->download($class_details['data']['classSection']['video'],$class_path,$file_name); } if(!empty($class_details['data']['classSection']['courseware'])){ - $this->download($class_details['data']['classSection']['courseware'],$class_path); + $file_name = urldecode(basename($class_details['data']['classSection']['courseware'])); + $downloadurl = $class_path . '/' . $file_name . '-下载地址.txt'; + $this->savetxt($downloadurl,$class_details['data']['classSection']['courseware']); + $this->download($class_details['data']['classSection']['courseware'],$class_path,$file_name); } if(!empty($class_details['data']['classSection']['construction_draw'])){ - $this->download($class_details['data']['classSection']['construction_draw'],$class_path); + $file_name = urldecode(basename($class_details['data']['classSection']['construction_draw'])); + $downloadurl = $class_path . '/' . $file_name . '-下载地址.txt'; + $this->savetxt($downloadurl,$class_details['data']['classSection']['construction_draw']); + $this->download($class_details['data']['classSection']['construction_draw'],$class_path,$file_name); } if(!empty($class_details['data']['classSection']['construction_draw_3d'])){ - $this->download($class_details['data']['classSection']['construction_draw_3d'],$class_path); + $file_name = urldecode(basename($class_details['data']['classSection']['construction_draw_3d'])); + $downloadurl = $class_path . '/' . $file_name . '-下载地址.txt'; + $this->savetxt($downloadurl,urldecode($class_details['data']['classSection']['construction_draw_3d'])); + $this->download($class_details['data']['classSection']['construction_draw_3d'],$class_path,$file_name); } foreach($class_details['data']['classSection']['allEnclosure'] as $enclosure){ @@ -109,7 +125,7 @@ class Zm extends Command is_dir($storage) || mkdir($storage,0755,true); $downloadurl = $storage . '/' . urldecode(end($parts)) . '-下载地址.txt'; $this->savetxt($downloadurl,urldecode($enclosure['url'])); - // $this->download($enclosure['url'],$storage); + $this->download($enclosure['url'],$storage,basename($enclosure['url'])); } } } @@ -131,6 +147,16 @@ class Zm extends Command private function checkfile($url,$file) { dump($url,$file); + if(is_file($file)){ + $size = filesize($file); + if($size > 0){ + return true; + }else{ + dump('文件大小为0,重新下载'.$file); + unlink($file); + return 2; + } + } $key = 'zm_check_header_' . md5($url); try { if(($head = Cache::get($key,null)) === NULL ){ @@ -157,7 +183,6 @@ class Zm extends Command foreach ($headers as $name => $values) { $head[$name] = implode(', ', $values); } - dump($head); } catch (\GuzzleHttp\Exception\RequestException $e) { dump("文件head请求失败: " . $e->getMessage()); return 0; @@ -191,13 +216,20 @@ class Zm extends Command } return 3; } - protected function download($downloadurl,$dir,$filename = null) + protected function download($downloadurl,$dir,$filename) { + return; + $result = $this->checkfile($downloadurl,$dir . '/' . $filename); + + if($result === true){ + dump('文件已存在,跳过下载:' . $filename); + return; + } $num = 1; while($num > 0){ $activeDownloads = $this->aria2->getGlobalStat(); $num = intval($activeDownloads['result']['numWaiting']); - if($num > 10){ + if($num > 50){ dump('当前任务过多,等待任务数:',$num); sleep(1); }else{ @@ -314,6 +346,8 @@ class Zm extends Command return $this->getClassDetails($curr_id,$result['sign']); }else if($result['code'] == 0){ return $result; + }else if($result['code'] == -5){ + return false; }else{ dump($result['msg']); exit();