Merge branch 'master' of dev.sourcefabric.org:airtime

This commit is contained in:
paul.baranowski 2011-03-28 14:53:26 -04:00
commit 3001a3aede
4 changed files with 26 additions and 22 deletions

View File

@ -236,10 +236,6 @@ class ApiController extends Zend_Controller_Action
{ {
global $CC_CONFIG; global $CC_CONFIG;
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"])) if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
@ -251,16 +247,19 @@ class ApiController extends Zend_Controller_Action
$upload_dir = ini_get("upload_tmp_dir"); $upload_dir = ini_get("upload_tmp_dir");
$file = StoredFile::uploadFile($upload_dir); $file = StoredFile::uploadFile($upload_dir);
if(Application_Model_Preference::GetDoSoundCloudUpload())
{
$soundcloud = new ATSoundcloud();
$soundcloud->uploadTrack($file->getRealFilePath(), $file->getName());
}
$show_instance = $this->_getParam('show_instance'); $show_instance = $this->_getParam('show_instance');
$show = new ShowInstance($show_instance); $show_inst = new ShowInstance($show_instance);
$show->setRecordedFile($file->getId()); $show_inst->setRecordedFile($file->getId());
if(Application_Model_Preference::GetDoSoundCloudUpload())
{
$show = new Show($show_inst->getShowId());
$description = $show->getDescription();
$soundcloud = new ATSoundcloud();
$soundcloud->uploadTrack($file->getRealFilePath(), $file->getName(), $description);
}
$this->view->id = $file->getId(); $this->view->id = $file->getId();
} }

View File

@ -28,14 +28,18 @@ class ATSoundcloud {
return $token; return $token;
} }
public function uploadTrack($filepath, $filename) public function uploadTrack($filepath, $filename, $description, $tags=array())
{ {
if($this->getToken()) if($this->getToken())
{ {
$tags = join(" ", $tags);
$track_data = array( $track_data = array(
'track[sharing]' => 'private', 'track[sharing]' => 'private',
'track[title]' => $filename, 'track[title]' => $filename,
'track[asset_data]' => '@' . $filepath 'track[asset_data]' => '@' . $filepath,
'track[tag_list]' => $tags,
'track[description]' => $description
); );
try { try {
@ -46,7 +50,6 @@ class ATSoundcloud {
} }
catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
echo $e->getMessage(); echo $e->getMessage();
echo var_dump($track_data);
} }
} }
} }

View File

@ -291,9 +291,9 @@ class AirTimeApiClient(ApiClientInterface):
response = '' response = ''
try: try:
url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"] url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
#logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
logger.debug(url) logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
response = urllib.urlopen(url) response = urllib.urlopen(url)
response = json.loads(response.read()) response = json.loads(response.read())
logger.info("shows %s", response) logger.info("shows %s", response)
@ -308,9 +308,8 @@ class AirTimeApiClient(ApiClientInterface):
response = '' response = ''
try: try:
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"] url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
#logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
logger.debug(url) logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
request = urllib2.Request(url, data, headers) request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request).read().strip() response = urllib2.urlopen(request).read().strip()

View File

@ -109,14 +109,14 @@ class Record():
show_end = getDateTimeObj(show[u'ends']) show_end = getDateTimeObj(show[u'ends'])
time_delta = show_end - show_starts time_delta = show_end - show_starts
self.shows_to_record[show[u'starts']] = [time_delta, show[u'instance_id']] self.shows_to_record[show[u'starts']] = [time_delta, show[u'instance_id'], show[u'name']]
def check_record(self): def check_record(self):
tnow = datetime.datetime.now() tnow = datetime.datetime.now()
sorted_show_keys = sorted(self.shows_to_record.keys()) sorted_show_keys = sorted(self.shows_to_record.keys())
print sorted_show_keys
start_time = sorted_show_keys[0] start_time = sorted_show_keys[0]
next_show = getDateTimeObj(start_time) next_show = getDateTimeObj(start_time)
@ -132,7 +132,10 @@ class Record():
show_length = self.shows_to_record[start_time][0] show_length = self.shows_to_record[start_time][0]
show_instance = self.shows_to_record[start_time][1] show_instance = self.shows_to_record[start_time][1]
show = ShowRecorder(show_instance, show_length.seconds, start_time, filetype="mp3") show_name = self.shows_to_record[start_time][2]
filename = show_name+"-"+start_time
show = ShowRecorder(show_instance, show_length.seconds, filename, filetype="mp3")
show.start() show.start()
#remove show from shows to record. #remove show from shows to record.