From 1cdbce55a715a006663783aca814c062a3d522a2 Mon Sep 17 00:00:00 2001 From: naomiaro Date: Sun, 3 Apr 2011 22:32:11 -0400 Subject: [PATCH] CC-2125 : Soundcloud: ability to retry to upload if a recorded show in the past does not have a soundcloud file id, context menu action appears to upload to soundcloud if it is enabled in preferences. if a recorded file is on soundcloud the soundcloud icon replaces the record icon. --- .../controllers/ScheduleController.php | 57 +++++++++++++++++- application/models/Shows.php | 20 ++++++ public/css/images/upload-icon.gif | Bin 0 -> 1188 bytes public/css/styles.css | 7 ++- .../schedule/full-calendar-functions.js | 18 +++--- public/js/airtime/schedule/schedule.js | 24 ++++++++ 6 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 public/css/images/upload-icon.gif diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index f6f4ee924..85d5b13ff 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -25,6 +25,7 @@ class ScheduleController extends Zend_Controller_Action ->addActionContext('edit-show', 'json') ->addActionContext('add-show', 'json') ->addActionContext('cancel-show', 'json') + ->addActionContext('upload-to-sound-cloud', 'json') ->initContext(); $this->sched_sess = new Zend_Session_Namespace("schedule"); @@ -145,6 +146,52 @@ class ScheduleController extends Zend_Controller_Action } } + 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->getRealFilePath(), $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']); + } + } + } + public function makeContextMenuAction() { $id = $this->_getParam('id'); @@ -174,10 +221,18 @@ class ScheduleController extends Zend_Controller_Action 'callback' => 'window["buildContentDialog"]'), 'title' => 'Show Content'); } + if (strtotime($show->getShowEnd()) <= strtotime($today_timestamp) + && is_null($show->getSoundCloudFileId()) + && Application_Model_Preference::GetDoSoundCloudUpload()) { + $menu[] = array('action' => array('type' => 'fn', + 'callback' => "window['uploadToSoundCloud']($id)"), + 'title' => 'Upload to Soundcloud'); + } + if (strtotime($show->getShowStart()) <= strtotime($today_timestamp) && strtotime($today_timestamp) < strtotime($show->getShowEnd()) && - $user->isAdmin()) { + $user->isAdmin() && !$show->isRecorded()) { $menu[] = array('action' => array('type' => 'fn', 'callback' => "window['confirmCancelShow']($id)"), 'title' => 'Cancel Current Show'); diff --git a/application/models/Shows.php b/application/models/Shows.php index 8db07c8ec..a7ee8d232 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -648,6 +648,26 @@ class ShowInstance { return $showInstance->getDbSoundCloudId(); } + public function getRecordedFile() + { + $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); + $file_id = $showInstance->getDbRecordedFile(); + + if(isset($file_id)) { + $file = StoredFile::Recall($file_id); + + if (PEAR::isError($file)) { + return null; + } + + if(file_exists($file->getRealFilePath())) { + return $file; + } + } + + return null; + } + public function setShowStart($start) { $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); diff --git a/public/css/images/upload-icon.gif b/public/css/images/upload-icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..45b4f81a9b07809afd31a9770df6bcc1c65780b8 GIT binary patch literal 1188 zcmZ?wbhEHbhoft^E!f#HBdBP*wrhyugHgN;1=UL_WW4h=0rx_(nS zCN4VEFKf%i!vWIGil$o&S+~!M4+@8y1?2fe6dV>gbO{)H@dz+HbZVASmXeVWKxk)S zU}0bbLIw^=nD!<%emN0^1cwF&W(lhn3j+m&YDNZj1`eQ`88}24m{}wo3V=>$V&@P@ z5O6ry%F4`yP{{x{R}7-E;Xo6IAeX>`35r17@@y=~N*RGhasY+J7}!}j6ec`qU}R!Z z2&wp>0Q8|8s!|51Yb8Lg6;L?9z{tcQ`aV*eW4q!Mu01B`P Q0Ch1qHS;jDurOEy0I9`Cm;e9( literal 0 HcmV?d00001 diff --git a/public/css/styles.css b/public/css/styles.css index 4ef4decee..2049c042b 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -1511,6 +1511,11 @@ div.success{ background:url(images/icon_soundcloud.png) no-repeat 0 0; width:21px; } +.small-icon.progress { + background:url(images/upload-icon.gif) no-repeat; + background-color:black; + background-position:center; +} .medium-icon { display:block; width:25px; @@ -1585,4 +1590,4 @@ dd.radio-inline-list, .preferences dd.radio-inline-list { } .preferences dd.block-display .input_text_area, .preferences dd.block-display .input_text { width: 99.5%; -} \ No newline at end of file +} diff --git a/public/js/airtime/schedule/full-calendar-functions.js b/public/js/airtime/schedule/full-calendar-functions.js index ab8eb34c9..86fc03b78 100644 --- a/public/js/airtime/schedule/full-calendar-functions.js +++ b/public/js/airtime/schedule/full-calendar-functions.js @@ -148,8 +148,8 @@ function viewDisplay( view ) { function eventRender(event, element, view) { - //only put progress bar on shows that aren't being recorded and are not a rebroadcast. - if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.record === 0 /* && event.rebroadcast === 0 */) { + //only put progress bar on shows that aren't being recorded. + if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.record === 0) { var div = $('
'); div .height('5px') @@ -168,15 +168,17 @@ function eventRender(event, element, view) { } //add the record/rebroadcast icons if needed. - if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.record === 1) { + + //record icon (only if not on soundcloud, will always be true for future events) + if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.record === 1 && event.soundcloud_id === -1) { $(element).find(".fc-event-time").after(''); } - if(view.name === 'month' && event.record === 1) { + if(view.name === 'month' && event.record === 1 && event.soundcloud_id === -1) { $(element).find(".fc-event-title").after(''); } - + //rebroadcast icon if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.rebroadcast === 1) { $(element).find(".fc-event-time").after(''); @@ -185,12 +187,12 @@ function eventRender(event, element, view) { $(element).find(".fc-event-title").after(''); } - - if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.soundcloud_id != -1 && event.record === 1) { + //soundcloud icon + if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.soundcloud_id !== -1 && event.record === 1) { $(element).find(".fc-event-time").after(''); } - if(view.name === 'month' && event.soundcloud_id != -1 && event.record === 1) { + if(view.name === 'month' && event.soundcloud_id !== -1 && event.record === 1) { $(element).find(".fc-event-title").after(''); } diff --git a/public/js/airtime/schedule/schedule.js b/public/js/airtime/schedule/schedule.js index 79c364e4c..9a9840a83 100644 --- a/public/js/airtime/schedule/schedule.js +++ b/public/js/airtime/schedule/schedule.js @@ -165,6 +165,30 @@ function confirmCancelShow(show_instance_id){ } } +function uploadToSoundCloud(show_instance_id){ + + var url = "/Schedule/upload-to-sound-cloud"; + var span = $(window.triggerElement).find(".recording"); + + span.removeClass("recording") + .addClass("progress"); + + $.post(url, + {id: show_instance_id, format: "json"}, + function(data){ + if(data.error) { + span.removeClass("progress") + .addClass("recording"); + + alert(data.error); + return; + } + span.removeClass("progress") + .addClass("soundcloud"); + }); + +} + function buildContentDialog(json){ var dialog = $(json.dialog);