コード例 #1
0
 public function handleWatchedDirMissingAction()
 {
     $request = $this->getRequest();
     $dir = base64_decode($request->getParam('dir'));
     Application_Model_MusicDir::removeWatchedDir($dir, false);
 }
コード例 #2
0
ファイル: StoredFile.php プロジェクト: nidzix/Airtime
 public static function copyFileToStor($p_targetDir, $fileName, $tempname)
 {
     $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
     Logging::info('copyFileToStor: moving file ' . $audio_file);
     $storDir = Application_Model_MusicDir::getStorDir();
     $stor = $storDir->getDirectory();
     // check if "organize" dir exists and if not create one
     if (!file_exists($stor . "/organize")) {
         if (!mkdir($stor . "/organize", 0777)) {
             return array("code" => 109, "message" => "Failed to create 'organize' directory.");
         }
     }
     if (chmod($audio_file, 0644) === false) {
         Logging::info("Warning: couldn't change permissions of {$audio_file} to 0644");
     }
     // Check if we have enough space before copying
     if (!self::isEnoughDiskSpaceToCopy($stor, $audio_file)) {
         $freeSpace = disk_free_space($stor);
         return array("code" => 107, "message" => "The file was not uploaded, there is\n                " . $freeSpace . "MB of disk space left and the file you are\n                uploading has a size of  " . $fileSize . "MB.");
     }
     // Check if liquidsoap can play this file
     if (!self::liquidsoapFilePlayabilityTest($audio_file)) {
         return array("code" => 110, "message" => "This file appears to be corrupted and will not\n                be added to media library.");
     }
     // Did all the checks for real, now trying to copy
     $audio_stor = Application_Common_OsPath::join($stor, "organize", $fileName);
     $user = Application_Model_User::getCurrentUser();
     if (is_null($user)) {
         $uid = Application_Model_User::getFirstAdminId();
     } else {
         $uid = $user->getId();
     }
     $id_file = "{$audio_stor}.identifier";
     if (file_put_contents($id_file, $uid) === false) {
         Logging::info("Could not write file to identify user: '******'");
         Logging::info("Id file path: '{$id_file}'");
         Logging::info("Defaulting to admin (no identification file was\n                written)");
     } else {
         Logging::info("Successfully written identification file for\n                uploaded '{$audio_stor}'");
     }
     Logging::info("copyFileToStor: moving file {$audio_file} to {$audio_stor}");
     // Martin K.: changed to rename: Much less load + quicker since this is
     // an atomic operation
     if (@rename($audio_file, $audio_stor) === false) {
         //something went wrong likely there wasn't enough space in .
         //the audio_stor to move the file too warn the user that   .
         //the file wasn't uploaded and they should check if there  .
         //is enough disk space                                     .
         unlink($audio_file);
         //remove the file after failed rename
         unlink($id_file);
         // Also remove the identifier file
         return array("code" => 108, "message" => "\n                The file was not uploaded, this error can occur if the computer\n                hard drive does not have enough disk space or the stor\n                directory does not have correct write permissions.");
     }
     // Now that we successfully added this file, we will add another tag
     // file that will identify the user that owns it
     return null;
 }
コード例 #3
0
 public function removeWatchDirectoryAction()
 {
     $chosen = $this->getRequest()->getParam("dir");
     $dir = Application_Model_MusicDir::removeWatchedDir($chosen);
     $watched_dirs_form = new Application_Form_WatchedDirPreferences();
     $this->view->subform = $watched_dirs_form->render();
 }
コード例 #4
0
ファイル: Systemstatus.php プロジェクト: nidzix/Airtime
 public static function GetDiskInfo()
 {
     $partions = array();
     if (isset($_SERVER['AIRTIME_SRV'])) {
         //connect to DB and find how much total space user has allocated.
         $totalSpace = Application_Model_Preference::GetDiskQuota();
         $storPath = Application_Model_MusicDir::getStorDir()->getDirectory();
         list($usedSpace, ) = preg_split("/[\\s]+/", exec("du -bs {$storPath}"));
         $partitions[$totalSpace]->totalSpace = $totalSpace;
         $partitions[$totalSpace]->totalFreeSpace = $totalSpace - $usedSpace;
         Logging::info($partitions[$totalSpace]->totalFreeSpace);
     } else {
         /* First lets get all the watched directories. Then we can group them
          * into the same partitions by comparing the partition sizes. */
         $musicDirs = Application_Model_MusicDir::getWatchedDirs();
         $musicDirs[] = Application_Model_MusicDir::getStorDir();
         foreach ($musicDirs as $md) {
             $totalSpace = disk_total_space($md->getDirectory());
             if (!isset($partitions[$totalSpace])) {
                 $partitions[$totalSpace] = new StdClass();
                 $partitions[$totalSpace]->totalSpace = $totalSpace;
                 $partitions[$totalSpace]->totalFreeSpace = disk_free_space($md->getDirectory());
             }
             $partitions[$totalSpace]->dirs[] = $md->getDirectory();
         }
     }
     return array_values($partitions);
 }
コード例 #5
0
 public static function GetDiskInfo()
 {
     $partitions = array();
     /* First lets get all the watched directories. Then we can group them
      * into the same partitions by comparing the partition sizes. */
     $musicDirs = Application_Model_MusicDir::getWatchedDirs();
     $musicDirs[] = Application_Model_MusicDir::getStorDir();
     foreach ($musicDirs as $md) {
         $totalSpace = disk_total_space($md->getDirectory());
         if (!isset($partitions[$totalSpace])) {
             $partitions[$totalSpace] = new StdClass();
             $partitions[$totalSpace]->totalSpace = $totalSpace;
             $partitions[$totalSpace]->totalFreeSpace = disk_free_space($md->getDirectory());
         }
         $partitions[$totalSpace]->dirs[] = $md->getDirectory();
     }
     return array_values($partitions);
 }
コード例 #6
0
ファイル: MusicDir.php プロジェクト: nidzix/Airtime
 /** There are 2 cases where this function can be called.
  * 1. When watched dir was removed
  * 2. When some dir was watched, but it was unmounted
  *
  *  In case of 1, $userAddedWatchedDir should be true
  *  In case of 2, $userAddedWatchedDir should be false
  *
  *  When $userAddedWatchedDir is true, it will set "Watched" flag to false
  *  otherwise, it will set "Exists" flag to true
  **/
 public static function removeWatchedDir($p_dir, $userAddedWatchedDir = true)
 {
     //make sure that $p_dir has a trailing "/"
     $real_path = Application_Common_OsPath::normpath($p_dir) . "/";
     if ($real_path != "/") {
         $p_dir = $real_path;
     }
     $dir = Application_Model_MusicDir::getDirByPath($p_dir);
     if (is_null($dir)) {
         return array("code" => 1, "error" => "'{$p_dir}' doesn't exist in the watched list.");
     } else {
         $dir->remove($userAddedWatchedDir);
         $data = array();
         $data["directory"] = $p_dir;
         Application_Model_RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
         return array("code" => 0);
     }
 }
コード例 #7
0
ファイル: LibraryController.php プロジェクト: nidzix/Airtime
 public function getFileMetadataAction()
 {
     $id = $this->_getParam('id');
     $type = $this->_getParam('type');
     try {
         if ($type == "audioclip") {
             $file = Application_Model_StoredFile::Recall($id);
             $this->view->type = $type;
             $md = $file->getMetadata();
             foreach ($md as $key => $value) {
                 if ($key == 'MDATA_KEY_DIRECTORY') {
                     $musicDir = Application_Model_MusicDir::getDirByPK($value);
                     $md['MDATA_KEY_FILEPATH'] = Application_Common_OsPath::join($musicDir->getDirectory(), $md['MDATA_KEY_FILEPATH']);
                 }
             }
             $formatter = new SamplerateFormatter($md["MDATA_KEY_SAMPLERATE"]);
             $md["MDATA_KEY_SAMPLERATE"] = $formatter->format();
             $formatter = new BitrateFormatter($md["MDATA_KEY_BITRATE"]);
             $md["MDATA_KEY_BITRATE"] = $formatter->format();
             $formatter = new LengthFormatter($md["MDATA_KEY_DURATION"]);
             $md["MDATA_KEY_DURATION"] = $formatter->format();
             $this->view->md = $md;
         } elseif ($type == "playlist") {
             $file = new Application_Model_Playlist($id);
             $this->view->type = $type;
             $md = $file->getAllPLMetaData();
             $formatter = new LengthFormatter($md["dcterms:extent"]);
             $md["dcterms:extent"] = $formatter->format();
             $this->view->md = $md;
             $this->view->contents = $file->getContents();
         } elseif ($type == "block") {
             $block = new Application_Model_Block($id);
             $this->view->type = $type;
             $md = $block->getAllPLMetaData();
             $formatter = new LengthFormatter($md["dcterms:extent"]);
             $md["dcterms:extent"] = $formatter->format();
             $this->view->md = $md;
             if ($block->isStatic()) {
                 $this->view->blType = 'Static';
                 $this->view->contents = $block->getContents();
             } else {
                 $this->view->blType = 'Dynamic';
                 $this->view->contents = $block->getCriteria();
             }
             $this->view->block = $block;
         } elseif ($type == "stream") {
             $webstream = CcWebstreamQuery::create()->findPK($id);
             $ws = new Application_Model_Webstream($webstream);
             $md = $ws->getMetadata();
             $this->view->md = $md;
             $this->view->type = $type;
         }
     } catch (Exception $e) {
         Logging::info($e->getMessage());
     }
 }