Exemple #1
0
 protected function downloadFileInWindowsNT(TFFile $file)
 {
     $client = new Client();
     try {
         $response = $client->get($file->source, ['verify' => false]);
     } catch (\Exception $e) {
         $error = 'TFDownloader: Downloading file failed, url is %s, msg is %s.';
         $error = sprintf($error, $file->source, $e->getMessage());
         Log::error($error);
         $file->state = 'error';
         $file->error = $error;
         $file->save();
         return;
     }
     if ($response->getStatusCode() == 200) {
         $location = 'file/' . $file->name;
         Storage::put($location, $response->getBody());
         $file->state = 'downloaded';
         $file->location = $location;
         $file->save();
         return;
     } else {
         $error = 'TFDownloader: Bad HTTP response code in downloading videos, url is %s, status code is %d.';
         $error = sprintf($error, $file->source, $response->getStatusCode());
         Log::error($error);
         $file->state = 'error';
         $file->error = $error;
         $file->save();
         return;
     }
 }
Exemple #2
0
 public function getTestpreg()
 {
     $file = new TFFile();
     $url = 'https://45.media.tumblr.com/e30abb759aaaaa246f4051678dd0697b/tumblr_o2t8a9VzDu1qb6v6ro2_400.gif';
     echo $url;
     echo '<br/>';
     $file->parseImageUrlToHighQuality($url);
     return $file->source;
 }
Exemple #3
0
 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);
 }
Exemple #4
0
 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();
     }
 }