CC-1799 : Live Studio Playout from media library (pytagsfs)
if a tag is edited by easytag, the change is now reflected in airtime database.
This commit is contained in:
parent
f64a1aae34
commit
6834ecca76
|
@ -8,10 +8,10 @@ class ApiController extends Zend_Controller_Action
|
||||||
/* Initialize action controller here */
|
/* Initialize action controller here */
|
||||||
$context = $this->_helper->getHelper('contextSwitch');
|
$context = $this->_helper->getHelper('contextSwitch');
|
||||||
$context->addActionContext('version', 'json')
|
$context->addActionContext('version', 'json')
|
||||||
->addActionContext('recorded-shows', 'json')
|
->addActionContext('recorded-shows', 'json')
|
||||||
->addActionContext('upload-recorded', 'json')
|
->addActionContext('upload-recorded', 'json')
|
||||||
->addActionContext('reload-metadata', 'json')
|
->addActionContext('reload-metadata', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
|
@ -332,7 +332,20 @@ class ApiController extends Zend_Controller_Action
|
||||||
|
|
||||||
$md = $this->_getParam('md');
|
$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!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -543,16 +543,25 @@ class StoredFile {
|
||||||
public function replaceDbMetadata($p_values)
|
public function replaceDbMetadata($p_values)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
$data = array();
|
||||||
foreach ($p_values as $category => $value) {
|
foreach ($p_values as $category => $value) {
|
||||||
$escapedValue = pg_escape_string($value);
|
$escapedValue = pg_escape_string($value);
|
||||||
$columnName = $category;
|
$columnName = $category;
|
||||||
if (!is_null($columnName)) {
|
if (!is_null($columnName)) {
|
||||||
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
|
$data[] = "$columnName='$escapedValue'";
|
||||||
." SET $columnName='$escapedValue'"
|
|
||||||
." WHERE gunid = '".$this->gunid."'";
|
|
||||||
$CC_DBC->query($sql);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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()
|
public function clearMetadata()
|
||||||
|
|
|
@ -29,7 +29,25 @@ def api_client_factory(config):
|
||||||
print 'API Client "'+config["api_client"]+'" not supported. Please check your config file.'
|
print 'API Client "'+config["api_client"]+'" not supported. Please check your config file.'
|
||||||
print
|
print
|
||||||
sys.exit()
|
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:
|
class ApiClientInterface:
|
||||||
|
|
||||||
# Implementation: optional
|
# Implementation: optional
|
||||||
|
@ -159,7 +177,6 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
status, items = self.get_schedule('2010-01-01-00-00-00', '2011-01-01-00-00-00')
|
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
|
response = None
|
||||||
try:
|
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"])
|
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"])
|
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)
|
req = urllib2.Request(url, data)
|
||||||
response = urllib2.urlopen(req)
|
|
||||||
|
response = urllib2.urlopen(req).read()
|
||||||
response = json.loads(response.read())
|
logger.info("update media %s", response)
|
||||||
|
response = json.loads(response)
|
||||||
logger.info("update media %s", response)
|
logger.info("update media %s", response)
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
|
@ -84,12 +84,12 @@ class MediaMonitor(ProcessEvent):
|
||||||
gunid = event.name.split('.')[0]
|
gunid = event.name.split('.')[0]
|
||||||
|
|
||||||
md = {'gunid':gunid, 'md5':md5}
|
md = {'gunid':gunid, 'md5':md5}
|
||||||
|
|
||||||
file_info = mutagen.File(event.pathname, easy=True)
|
file_info = mutagen.File(event.pathname, easy=True)
|
||||||
attrs = self.mutagen2airtime
|
attrs = self.mutagen2airtime
|
||||||
for key in file_info.keys() :
|
for key in file_info.keys() :
|
||||||
if key in attrs :
|
if key in attrs :
|
||||||
md[attrs[key]] = file_info[key]
|
md[attrs[key]] = file_info[key][0]
|
||||||
|
|
||||||
data = {'md': md}
|
data = {'md': md}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue