CC-1799 : Live Studio Playout from media library (pytagsfs)

sending a file's metadata to airtime when it is modified
This commit is contained in:
Naomi 2011-04-25 17:34:58 -04:00 committed by martin
parent 52efc79f8c
commit 15a2022418
4 changed files with 45 additions and 16 deletions

View File

@ -10,6 +10,7 @@ class ApiController extends Zend_Controller_Action
$context->addActionContext('version', 'json')
->addActionContext('recorded-shows', 'json')
->addActionContext('upload-recorded', 'json')
->addActionContext('reload-metadata', 'json')
->initContext();
}
@ -121,7 +122,7 @@ class ApiController extends Zend_Controller_Action
"nextShow"=>Show_DAL::GetNextShows($timeNow, 5),
"timezone"=> date("T"),
"timezoneOffset"=> date("Z"));
//echo json_encode($result);
header("Content-type: text/javascript");
echo $_GET['callback'].'('.json_encode($result).')';
@ -314,11 +315,11 @@ class ApiController extends Zend_Controller_Action
}
}
$this->view->id = $file->getId();
$this->view->id = $file->getId();
}
public function reloadMetadataAction() {
global $CC_CONFIG;
$api_key = $this->_getParam('api_key');
@ -328,6 +329,10 @@ class ApiController extends Zend_Controller_Action
print 'You are not allowed to access this resource.';
exit;
}
$md = $this->_getParam('md');
$this->view->response = $md;
}
}

View File

@ -98,7 +98,7 @@ class ApiClientInterface:
def upload_recorded_show(self):
pass
def update_media_metadata(self):
def update_media_metadata(self, md):
pass
# Put here whatever tests you want to run to make sure your API is working
@ -350,18 +350,20 @@ class AirTimeApiClient(ApiClientInterface):
return response
def update_media_metadata(self):
def update_media_metadata(self, md):
logger = logging.getLogger()
response = None
try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["show_schedule_url"])
#url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_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)
url = url.replace("%%api_key%%", self.config["api_key"])
data = urllib.urlencode(md)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
response = urllib.urlopen(url)
response = json.loads(response.read())
logger.info("shows %s", response)
logger.info("update media %s", response)
except Exception, e:
logger.error("Exception: %s", e)

View File

@ -19,5 +19,5 @@ api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'
# URL to get the schedule of shows set to record
show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%'
# URL to tell Airtime to update file's meta data
update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%'

View File

@ -8,6 +8,7 @@ import time
import datetime
import os
import sys
from subprocess import Popen, PIPE, STDOUT
from configobj import ConfigObj
@ -34,20 +35,41 @@ except Exception, e:
mask = pyinotify.ALL_EVENTS
wm = WatchManager()
wdd = wm.add_watch('/srv/airtime/stor', mask, rec=True)
wdd = wm.add_watch('/srv/airtime/stor', mask, rec=True)
class MediaMonitor(ProcessEvent):
def my_init(self):
"""
Method automatically called from ProcessEvent.__init__(). Additional
keyworded arguments passed to ProcessEvent.__init__() are then
delegated to my_init().
"""
self.api_client = api_client.api_client_factory(config)
class PTmp(ProcessEvent):
def process_IN_CREATE(self, event):
if event.dir :
global wm
wdd = wm.add_watch(event.pathname, mask, rec=True)
#print wdd.keys()
print "%s: %s" % (event.maskname, os.path.join(event.path, event.name))
def process_IN_MODIFY(self, event):
if not event.dir :
print event.path
p = Popen(["pytags", event.pathname], stdout=PIPE, stderr=STDOUT)
output = p.stdout.read().decode("utf-8").strip()
print output.split("\n")
md = {'filepath':event.pathname}
for tag in output.split("\n")[2:] :
key,value = tag.split("=")
md[key] = value
data = {'md': md}
response = self.api_client.update_media_metadata(data)
print "%s: %s" % (event.maskname, os.path.join(event.path, event.name))
@ -59,7 +81,7 @@ if __name__ == '__main__':
print 'Media Monitor'
try:
notifier = Notifier(wm, PTmp(), read_freq=2, timeout=1)
notifier = Notifier(wm, MediaMonitor(), read_freq=2, timeout=1)
notifier.coalesce_events()
notifier.loop()
except KeyboardInterrupt: