예제 #1
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;
 }