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:
parent
52efc79f8c
commit
15a2022418
|
@ -10,6 +10,7 @@ class ApiController extends Zend_Controller_Action
|
||||||
$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')
|
||||||
->initContext();
|
->initContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +329,10 @@ class ApiController extends Zend_Controller_Action
|
||||||
print 'You are not allowed to access this resource.';
|
print 'You are not allowed to access this resource.';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$md = $this->_getParam('md');
|
||||||
|
|
||||||
|
$this->view->response = $md;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class ApiClientInterface:
|
||||||
def upload_recorded_show(self):
|
def upload_recorded_show(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_media_metadata(self):
|
def update_media_metadata(self, md):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Put here whatever tests you want to run to make sure your API is working
|
# Put here whatever tests you want to run to make sure your API is working
|
||||||
|
@ -350,18 +350,20 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def update_media_metadata(self):
|
def update_media_metadata(self, md):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
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["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"])
|
||||||
#url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_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"])
|
||||||
|
|
||||||
response = urllib.urlopen(url)
|
data = urllib.urlencode(md)
|
||||||
|
req = urllib2.Request(url, data)
|
||||||
|
response = urllib2.urlopen(req)
|
||||||
|
|
||||||
response = json.loads(response.read())
|
response = json.loads(response.read())
|
||||||
logger.info("shows %s", response)
|
logger.info("update media %s", response)
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error("Exception: %s", e)
|
logger.error("Exception: %s", e)
|
||||||
|
|
|
@ -19,5 +19,5 @@ api_base = 'api'
|
||||||
# URL to get the version number of the server API
|
# URL to get the version number of the server API
|
||||||
version_url = 'version/api_key/%%api_key%%'
|
version_url = 'version/api_key/%%api_key%%'
|
||||||
|
|
||||||
# URL to get the schedule of shows set to record
|
# URL to tell Airtime to update file's meta data
|
||||||
show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%'
|
update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%'
|
||||||
|
|
|
@ -8,6 +8,7 @@ import time
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
|
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
@ -36,7 +37,16 @@ mask = pyinotify.ALL_EVENTS
|
||||||
wm = WatchManager()
|
wm = WatchManager()
|
||||||
wdd = wm.add_watch('/srv/airtime/stor', mask, rec=True)
|
wdd = wm.add_watch('/srv/airtime/stor', mask, rec=True)
|
||||||
|
|
||||||
class PTmp(ProcessEvent):
|
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)
|
||||||
|
|
||||||
def process_IN_CREATE(self, event):
|
def process_IN_CREATE(self, event):
|
||||||
if event.dir :
|
if event.dir :
|
||||||
global wm
|
global wm
|
||||||
|
@ -47,7 +57,19 @@ class PTmp(ProcessEvent):
|
||||||
|
|
||||||
def process_IN_MODIFY(self, event):
|
def process_IN_MODIFY(self, event):
|
||||||
if not event.dir :
|
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))
|
print "%s: %s" % (event.maskname, os.path.join(event.path, event.name))
|
||||||
|
|
||||||
|
@ -59,7 +81,7 @@ if __name__ == '__main__':
|
||||||
print 'Media Monitor'
|
print 'Media Monitor'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
notifier = Notifier(wm, PTmp(), read_freq=2, timeout=1)
|
notifier = Notifier(wm, MediaMonitor(), read_freq=2, timeout=1)
|
||||||
notifier.coalesce_events()
|
notifier.coalesce_events()
|
||||||
notifier.loop()
|
notifier.loop()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
Loading…
Reference in New Issue