CC-2362:Recorded show wrong file name

- not finished yet. Temp commit
This commit is contained in:
james 2011-06-06 10:18:03 -04:00
parent c8219e3b97
commit 4247f8c7a7
3 changed files with 64 additions and 53 deletions

View file

@ -294,22 +294,46 @@ 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())
} 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++) {
for ($i=0; $i<$CC_CONFIG['soundcloud-connection-retries']; $i++) {
$show = new Show($show_inst->getShowId());
$description = $show->getDescription();
@ -333,13 +357,6 @@ class ApiController extends Zend_Controller_Action
sleep($CC_CONFIG['soundcloud-connection-wait']);
}
}
} 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.
}
$this->view->id = $file->getId();
}

View file

@ -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,16 +1812,12 @@ 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),
"filepath" => $audio_file,

View file

@ -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.