From 4247f8c7a7710eadd4fd3dbea994f64f3ba5488d Mon Sep 17 00:00:00 2001 From: james Date: Mon, 6 Jun 2011 10:18:03 -0400 Subject: [PATCH] CC-2362:Recorded show wrong file name - not finished yet. Temp commit --- .../application/controllers/ApiController.php | 79 +++++++++++-------- airtime_mvc/application/models/StoredFile.php | 30 +++---- python_apps/show-recorder/recorder.py | 8 +- 3 files changed, 64 insertions(+), 53 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index dce293b0d..f298a0052 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -294,51 +294,68 @@ class ApiController extends Zend_Controller_Action exit; } + $logger = Logging::getLogger(); + + $showCanceled = false; + $show_instance = $this->_getParam('show_instance'); + + $logger->info("Show instance:" . $show_instance); + $upload_dir = ini_get("upload_tmp_dir"); $file = StoredFile::uploadFile($upload_dir); - - $show_instance = $this->_getParam('show_instance'); - + + $show_name = ""; try { + $logger->info("before declare"); $show_inst = new ShowInstance($show_instance); - +$logger->info("after"); $show_inst->setRecordedFile($file->getId()); $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); - 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']); - } - } - } catch (Exception $e){ + } 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; + } + + $logger->info("Show name:" . $show_name); + + $tmpTitle = !(empty($show_name))?$show_name."-":""; + $tmpTitle .= $file->getName(); + $logger->info("Tmp title".$tmpTitle); + + $file->setMetadataValue(UI_MDATA_KEY_TITLE, $tmpTitle); + + 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->getRealFilePath(), $file->getName(), $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->getId(); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 370b27cdb..ff0d6f447 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -1693,8 +1693,8 @@ class StoredFile { return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results); } - public static function uploadFile($targetDir) { - + public static function uploadFile($p_targetDir) + { // HTTP headers for no cache etc header('Content-type: text/plain; charset=UTF-8'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); @@ -1704,7 +1704,7 @@ class StoredFile { header("Pragma: no-cache"); // Settings - //$targetDir = ini_get("upload_tmp_dir"); //. DIRECTORY_SEPARATOR . "plupload"; + //$p_targetDir = ini_get("upload_tmp_dir"); //. DIRECTORY_SEPARATOR . "plupload"; $cleanupTargetDir = false; // Remove old files $maxFileAge = 60 * 60; // Temp file age in seconds @@ -1721,13 +1721,13 @@ class StoredFile { //$fileName = preg_replace('/[^\w\._]+/', '', $fileName); // Create target dir - if (!file_exists($targetDir)) - @mkdir($targetDir); + if (!file_exists($p_targetDir)) + @mkdir($p_targetDir); // Remove old temp files - if (is_dir($targetDir) && ($dir = opendir($targetDir))) { + if (is_dir($p_targetDir) && ($dir = opendir($p_targetDir))) { while (($file = readdir($dir)) !== false) { - $filePath = $targetDir . DIRECTORY_SEPARATOR . $file; + $filePath = $p_targetDir . DIRECTORY_SEPARATOR . $file; // Remove temp files if they are older than the max age if (preg_match('/\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge)) @@ -1748,7 +1748,7 @@ class StoredFile { if (strpos($contentType, "multipart") !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { // Open temp file - $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); + $out = fopen($p_targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen($_FILES['file']['tmp_name'], "rb"); @@ -1767,7 +1767,7 @@ class StoredFile { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } else { // Open temp file - $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); + $out = fopen($p_targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); @@ -1783,7 +1783,7 @@ class StoredFile { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } - $audio_file = $targetDir . DIRECTORY_SEPARATOR . $fileName; + $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName; $md5 = md5_file($audio_file); $duplicate = StoredFile::RecallByMd5($md5); @@ -1812,18 +1812,14 @@ class StoredFile { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $metadata->getMessage() + '}}'); } - // #2196 no id tag -> use the original filename - if (basename($audio_file) == $metadata[UI_MDATA_KEY_TITLE]) { + // no id3 title tag -> use the original filename for title + if (empty($metadata[UI_MDATA_KEY_TITLE])) { $metadata[UI_MDATA_KEY_TITLE] = basename($audio_file); $metadata[UI_MDATA_KEY_FILENAME] = basename($audio_file); } - // setMetadataBatch doesnt like these values - unset($metadata['audio']); - unset($metadata['playtime_seconds']); - $values = array( - "filename" => basename($audio_file), + "filename" => basename($audio_file), "filepath" => $audio_file, "filetype" => "audioclip", "mime" => $metadata[UI_MDATA_KEY_FORMAT], diff --git a/python_apps/show-recorder/recorder.py b/python_apps/show-recorder/recorder.py index 367779a5a..8986275be 100644 --- a/python_apps/show-recorder/recorder.py +++ b/python_apps/show-recorder/recorder.py @@ -47,11 +47,10 @@ def getDateTimeObj(time): class ShowRecorder(Thread): - def __init__ (self, show_instance, filelength, show_name, start_time, filetype): + def __init__ (self, show_instance, filelength, start_time, filetype): Thread.__init__(self) self.api_client = api_client.api_client_factory(config) self.filelength = filelength - self.show_name = show_name self.start_time = start_time self.filetype = filetype self.show_instance = show_instance @@ -60,7 +59,7 @@ class ShowRecorder(Thread): def record_show(self): length = str(self.filelength)+".0" - filename = self.show_name+" "+self.start_time + filename = self.start_time filename = filename.replace(" ", "-") filepath = "%s%s.%s" % (config["base_recorded_files"], filename, self.filetype) @@ -154,9 +153,8 @@ class Record(): show_length = self.shows_to_record[start_time][0] show_instance = self.shows_to_record[start_time][1] - show_name = self.shows_to_record[start_time][2] - self.sr = ShowRecorder(show_instance, show_length.seconds, show_name, start_time, filetype="mp3") + self.sr = ShowRecorder(show_instance, show_length.seconds, start_time, filetype="mp3") self.sr.start() #remove show from shows to record.