public function uploadToSoundCloudAction()
 {
     global $CC_CONFIG;
     $show_instance = $this->_getParam('id');
     $show_inst = new ShowInstance($show_instance);
     $file = $show_inst->getRecordedFile();
     if (is_null($file)) {
         $this->view->error = "Recorded file does not exist";
         return;
     }
     $show_name = $show_inst->getName();
     $show_genre = $show_inst->getGenre();
     $show_start_time = $show_inst->getShowStart();
     if (Application_Model_Preference::GetDoSoundCloudUpload()) {
         for ($i = 0; $i < $CC_CONFIG['soundcloud-connection-retries']; $i++) {
             $show = new Show($show_inst->getShowId());
             $description = $show->getDescription();
             $hosts = $show->getHosts();
             $tags = array_merge($hosts, array($show_name));
             try {
                 $soundcloud = new ATSoundcloud();
                 $soundcloud_id = $soundcloud->uploadTrack($file->getFilePath(), $file->getName(), $description, $tags, $show_start_time, $show_genre);
                 $show_inst->setSoundCloudFileId($soundcloud_id);
                 $this->view->soundcloud_id = $soundcloud_id;
                 break;
             } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
                 $code = $e->getHttpCode();
                 if (!in_array($code, array(0, 100))) {
                     break;
                 }
             }
             sleep($CC_CONFIG['soundcloud-connection-wait']);
         }
     }
 }
示例#2
0
 public function uploadRecordedAction()
 {
     global $CC_CONFIG;
     $api_key = $this->_getParam('api_key');
     if (!in_array($api_key, $CC_CONFIG["apiKey"])) {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource.';
         exit;
     }
     //this file id is the recording for this show instance.
     $show_instance_id = $this->_getParam('showinstanceid');
     $file_id = $this->_getParam('fileid');
     $this->view->fileid = $file_id;
     $this->view->showinstanceid = $show_instance_id;
     $showCanceled = false;
     $file = StoredFile::Recall($file_id);
     //$show_instance  = $this->_getParam('show_instance');
     $show_name = null;
     try {
         $show_inst = new ShowInstance($show_instance_id);
         $show_inst->setRecordedFile($file_id);
         $show_name = $show_inst->getName();
         $show_genre = $show_inst->getGenre();
         $show_start_time = $show_inst->getShowStart();
     } catch (Exception $e) {
         //we've reached here probably because the show was
         //cancelled, and therefore the show instance does not
         //exist anymore (ShowInstance constructor threw this error).
         //We've done all we can do (upload the file and put it in
         //the library), now lets just return.
         $showCanceled = true;
     }
     if (isset($show_name)) {
         $tmpTitle = "{$show_name}-{$show_start_time}";
         $tmpTitle = str_replace(" ", "-", $tmpTitle);
     } else {
         $tmpTitle = $file->getName();
     }
     $file->setMetadataValue('MDATA_KEY_TITLE', $tmpTitle);
     $file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder");
     $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', null);
     if (!$showCanceled && Application_Model_Preference::GetDoSoundCloudUpload()) {
         for ($i = 0; $i < $CC_CONFIG['soundcloud-connection-retries']; $i++) {
             $show = new Show($show_inst->getShowId());
             $description = $show->getDescription();
             $hosts = $show->getHosts();
             $tags = array_merge($hosts, array($show_name));
             try {
                 $soundcloud = new ATSoundcloud();
                 $soundcloud_id = $soundcloud->uploadTrack($file->getFilePath(), $tmpTitle, $description, $tags, $show_start_time, $show_genre);
                 $show_inst->setSoundCloudFileId($soundcloud_id);
                 break;
             } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
                 $code = $e->getHttpCode();
                 if (!in_array($code, array(0, 100))) {
                     break;
                 }
             }
             sleep($CC_CONFIG['soundcloud-connection-wait']);
         }
     }
     $this->view->id = $file_id;
 }