diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 307f116ee..a6f0825b7 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -8,10 +8,10 @@ class ApiController extends Zend_Controller_Action /* Initialize action controller here */ $context = $this->_helper->getHelper('contextSwitch'); $context->addActionContext('version', 'json') - ->addActionContext('recorded-shows', 'json') - ->addActionContext('upload-recorded', 'json') - ->addActionContext('reload-metadata', 'json') - ->initContext(); + ->addActionContext('recorded-shows', 'json') + ->addActionContext('upload-recorded', 'json') + ->addActionContext('reload-metadata', 'json') + ->initContext(); } public function indexAction() @@ -332,7 +332,20 @@ class ApiController extends Zend_Controller_Action $md = $this->_getParam('md'); - $this->view->response = $md; + $file = StoredFile::Recall(null, $md['gunid']); + if (PEAR::isError($file) || is_null($file)) { + $this->view->response = "File not in Airtime's Database"; + return; + } + + $res = $file->replaceDbMetadata($md); + + if (PEAR::isError($res)) { + $this->view->response = "Metadata Change Failed"; + } + else { + $this->view->response = "Success!"; + } } } diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 847e284f6..d5d4faf80 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -543,16 +543,25 @@ class StoredFile { public function replaceDbMetadata($p_values) { global $CC_CONFIG, $CC_DBC; + + $data = array(); foreach ($p_values as $category => $value) { $escapedValue = pg_escape_string($value); $columnName = $category; if (!is_null($columnName)) { - $sql = "UPDATE ".$CC_CONFIG["filesTable"] - ." SET $columnName='$escapedValue'" - ." WHERE gunid = '".$this->gunid."'"; - $CC_DBC->query($sql); + $data[] = "$columnName='$escapedValue'"; } } + + $data = join(",", $data); + $sql = "UPDATE ".$CC_CONFIG["filesTable"] + ." SET $data" + ." WHERE gunid = '".$this->gunid."'"; + $res = $CC_DBC->query($sql); + if (PEAR::isError($res)) { + $CC_DBC->query("ROLLBACK"); + return $res; + } } public function clearMetadata() diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 167ddccae..3661a8fdf 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -29,7 +29,25 @@ def api_client_factory(config): print 'API Client "'+config["api_client"]+'" not supported. Please check your config file.' print sys.exit() - + +def recursive_urlencode(d): + def recursion(d, base=None): + pairs = [] + + for key, value in d.items(): + if hasattr(value, 'values'): + pairs += recursion(value, key) + else: + new_pair = None + if base: + new_pair = "%s[%s]=%s" % (base, urllib.quote(unicode(key)), urllib.quote(unicode(value))) + else: + new_pair = "%s=%s" % (urllib.quote(unicode(key)), urllib.quote(unicode(value))) + pairs.append(new_pair) + return pairs + + return '&'.join(recursion(d)) + class ApiClientInterface: # Implementation: optional @@ -159,7 +177,6 @@ class AirTimeApiClient(ApiClientInterface): return version - def test(self): logger = logging.getLogger() status, items = self.get_schedule('2010-01-01-00-00-00', '2011-01-01-00-00-00') @@ -355,14 +372,16 @@ class AirTimeApiClient(ApiClientInterface): response = None try: url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_media_url"]) - logger.debug(url) + #logger.debug(url) url = url.replace("%%api_key%%", self.config["api_key"]) + logger.debug(url) - data = urllib.urlencode(md) + data = recursive_urlencode(md) req = urllib2.Request(url, data) - response = urllib2.urlopen(req) - - response = json.loads(response.read()) + + response = urllib2.urlopen(req).read() + logger.info("update media %s", response) + response = json.loads(response) logger.info("update media %s", response) except Exception, e: diff --git a/python_apps/pytag-fs/MediaMonitor.py b/python_apps/pytag-fs/MediaMonitor.py index 7f7fe8ad2..a0ed37a90 100644 --- a/python_apps/pytag-fs/MediaMonitor.py +++ b/python_apps/pytag-fs/MediaMonitor.py @@ -84,12 +84,12 @@ class MediaMonitor(ProcessEvent): gunid = event.name.split('.')[0] md = {'gunid':gunid, 'md5':md5} - + file_info = mutagen.File(event.pathname, easy=True) attrs = self.mutagen2airtime for key in file_info.keys() : if key in attrs : - md[attrs[key]] = file_info[key] + md[attrs[key]] = file_info[key][0] data = {'md': md}