Exemplo n.º 1
0
 static function AnalyzeFile($file)
 {
     @ini_set('max_execution_time', '0');
     @set_time_limit(0);
     $filename = is_string($file) ? $file : $file->GetLocalPath();
     $info = WPFB_Core::$settings->disable_id3 ? array() : self::GetEngine()->analyze($filename);
     if (!empty($_GET['debug'])) {
         wpfb_loadclass('Sync');
         WPFB_Sync::PrintDebugTrace("file_analyzed_" . $file->GetLocalPathRel());
     }
     return $info;
 }
Exemplo n.º 2
0
 /**
  * Intesive analysis of file contents. Does _not_ make changes to the file or store anything in the DB!
  * 
  * @param type $file
  * @return type
  */
 private static function analyzeFile($file)
 {
     @ini_set('max_execution_time', '0');
     @set_time_limit(0);
     $filename = is_string($file) ? $file : $file->GetLocalPath();
     $times = array();
     $times['analyze'] = microtime(true);
     $info = WPFB_Core::$settings->disable_id3 ? array() : self::GetEngine()->analyze($filename);
     if (!WPFB_Core::$settings->disable_id3 && class_exists('getid3_lib')) {
         getid3_lib::CopyTagsToComments($info);
     }
     if (!empty($_GET['debug'])) {
         wpfb_loadclass('Sync');
         WPFB_Sync::PrintDebugTrace("file_analyzed_" . $file->GetLocalPathRel());
     }
     $times['end'] = microtime(true);
     $t_keys = array_keys($times);
     $into['debug'] = array('timestamp' => $times[$t_keys[0]], 'timings' => array());
     for ($i = 1; $i < count($t_keys); $i++) {
         $info['debug']['timings'][$t_keys[$i - 1]] = round(($times[$t_keys[$i]] - $times[$t_keys[$i - 1]]) * 1000);
     }
     return $info;
 }
Exemplo n.º 3
0
 /**
  * 1. Checks if file is actually present and readable on file system and either sets file offline or completly removes it
  * 2. If file hash not set, calculate it
  * 3. Try to generate a thumbnail if it does not exists
  * 4. Update ID3 info (with _async_ RPC if enabled)
  * 
  * @param WPFB_File $file
  * @param bool $forced_refresh_thumb
  * @return bool
  */
 static function ScanFile($file, $forced_refresh_thumb = false, $allow_async = true)
 {
     if (!empty($_GET['debug'])) {
         WPFB_Sync::PrintDebugTrace("scanning_file:" . $file->GetLocalPathRel());
     }
     $file_path = $file->GetLocalPath();
     $tmp_file = false;
     if (!$file->IsLocal()) {
         $res = WPFB_Admin::SideloadFile($file->GetRemoteUri(), $file_path);
         if ($res['error']) {
             return false;
         }
         $tmp_file = true;
     } elseif (!is_file($file_path) || !is_readable($file_path)) {
         if (WPFB_Core::$settings->remove_missing_files) {
             $file->Remove();
             return true;
         } else {
             $file->file_offline = true;
             $file->file_mtime = 0;
             $file->file_rescan_pending = 1;
             $file->DbSave();
             return true;
         }
     }
     if (empty($file->file_hash)) {
         $file->file_hash = WPFB_Admin::GetFileHash($file->GetLocalPath());
     }
     if (empty($file->file_thumbnail) || $forced_refresh_thumb || !is_file($file->GetThumbPath())) {
         $file->Lock(true);
         $file->CreateThumbnail();
         // this only deltes old thumb if success
         $file->Lock(false);
         if (WPFB_Core::$settings->base_auto_thumb && empty($file->file_thumbnail)) {
             $thumb = false;
             $pwe = substr($file->GetLocalPath(), 0, strrpos($file->GetLocalPath(), '.') + 1);
             if ($pwe && (file_exists($thumb = $pwe . 'png') || file_exists($thumb = $pwe . 'jpg') || file_exists($thumb = $pwe . 'gif'))) {
                 $file->file_thumbnail = basename($thumb);
                 $dthumb = $file->GetThumbPath(true);
                 if ($dthumb != $thumb) {
                     $dir = dirname($dthumb);
                     if (!is_dir($dir)) {
                         WPFB_Admin::Mkdir($dir);
                     }
                     rename($thumb, $dthumb);
                 }
             }
         }
     }
     $file->file_rescan_pending = 1;
     $file->DBSave();
     WPFB_GetID3::UpdateCachedFileInfo($file);
     return true;
 }