public function zipAll() { $files = TFFile::where('state', '=', 'downloaded')->get(); $imageCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'image')->count(); $videoCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'video')->count(); if ($videoCount == 0 && $imageCount == 0) { Log::info('TFZipper : no file to be zipped.'); return; } $fileLocs = ""; $deleteLocs = []; foreach ($files as $file) { $deleteLocs[] = $file->location; $fileLocs .= ' ' . storage_path('app/' . $file->location); $file->state = 'zipped'; $file->save(); } $zipName = Carbon::now()->toDateString() . '.zip'; $zipLocs = 'zip/' . $zipName; $cmdPass = self::PASSWORD; $cmdTarget = storage_path('app/' . $zipLocs); $cmdLocs = $fileLocs; $cmd = ""; $sys = php_uname('s'); if ($sys == 'Windows NT') { $cmd = $this->rarCmd; } else { if ($sys == 'Linux') { $cmd = $this->zipCmd; } } $cmd = sprintf($cmd, $cmdPass, $cmdTarget, $cmdLocs); if ($sys == 'Windows NT') { $cmd = str_replace("/", "\\", $cmd); } $result = $this->runCmd($cmd); if (false == $result) { return; } $zip = new TFZip(); $zip->state = 'zipped'; $zip->error = ''; $zip->name = $zipName; $zip->date = Carbon::now()->toDateString(); $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB'; $zip->imageSize = $imageCount; $zip->videoSize = $videoCount; $zip->location = $zipLocs; $zip->save(); Storage::delete($deleteLocs); }
public function downloadNextFile() { $files = TFFile::where('state', '=', 'sniffed')->take(1)->get(); if ($files->count() == 0) { return; } $file = $files[0]; $sys = php_uname('s'); if ($sys == 'Windows NT') { $this->downloadFileInWindowsNT($file); } else { if ($sys == 'Linux') { $this->downloadFileInLinux($file); } } }
protected function sniffVideoOfDom(Dom $dom) { foreach ($dom->find('iframe') as $videoFrame) { // 获得iframe的地址 $videoFrameSrc = $videoFrame->getAttribute('src'); // 如果iframe的地址不存在,或者不含有特定字符串(用来判别是否是视频),废弃 if (empty($videoFrameSrc)) { continue; } if (!strstr($videoFrameSrc, 'https://www.tumblr.com/video/')) { continue; } try { // 如果已经检测了此视频,返回 $parentId = $videoFrame->getParent()->getAttribute('id'); $name = explode('_', $parentId)[3] . '.mp4'; if (TFFile::where('name', '=', $name)->count() != 0) { continue; } // 准备video的DOM $videoDom = $this->requestDom($videoFrameSrc); // 获取对应节点 $videoElem = $videoDom->find('video')[0]; $videoSource = $videoElem->find('source')[0]; } catch (\Exception $e) { $error = 'TFSniffer: Failed to parse video element, url is %s, msg is %s.'; $error = sprintf($error, $videoFrameSrc, $e->getMessage()); Log::error($error); continue; // pass this } // 开始读取数据 $video = new TFFile(); $video->type = 'video'; $video->state = 'sniffed'; $video->error = ''; $video->name = $name; $video->source = $videoSource->getAttribute('src'); $video->save(); } }