CC-3336: Refactor schedule API used by pypo
-removed export_source -rewrote GetScheduledPlaylists()
This commit is contained in:
parent
322d1bfa99
commit
99c24ed038
|
@ -468,6 +468,19 @@ class Application_Model_Schedule {
|
|||
return $rows;
|
||||
}
|
||||
|
||||
/*
|
||||
"2012-02-23-01-00-00":{
|
||||
"row_id":"1",
|
||||
"id":"caf951f6d8f087c3a90291a9622073f9",
|
||||
"uri":"http:\/\/localhost:80\/api\/get-media\/file\/caf951f6d8f087c3a90291a9622073f9.mp3",
|
||||
"fade_in":0,
|
||||
"fade_out":0,
|
||||
"cue_in":0,
|
||||
"cue_out":199.798,
|
||||
"start":"2012-02-23-01-00-00",
|
||||
"end":"2012-02-23-01-03-19"
|
||||
}
|
||||
* */
|
||||
|
||||
public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null){
|
||||
|
||||
|
@ -490,10 +503,38 @@ class Application_Model_Schedule {
|
|||
}
|
||||
|
||||
// Scheduler wants everything in a playlist
|
||||
$data = Application_Model_Schedule::GetItems($range_start, $range_end);
|
||||
$items = Application_Model_Schedule::GetItems($range_start, $range_end);
|
||||
|
||||
Logging::log(print_r($data, true));
|
||||
$data = array();
|
||||
$utcTimeZone = new DateTimeZone("UTC");
|
||||
|
||||
foreach ($items as $item){
|
||||
|
||||
$storedFile = Application_Model_StoredFile::Recall($item["file_id"]);
|
||||
$uri = $storedFile->getFileUrlUsingConfigAddress();
|
||||
|
||||
$showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
|
||||
$trackEndDateTime = new DateTime($item["ends"], $utcTimeZone);
|
||||
|
||||
if ($trackEndDateTime->getTimestamp() > $showEndDateTime->getTimestamp()){
|
||||
$diff = $trackEndDateTime->getTimestamp() - $showEndDateTime->getTimestamp();
|
||||
//assuming ends takes cue_out into assumption
|
||||
$item["cue_out"] = $item["cue_out"] - $diff;
|
||||
}
|
||||
|
||||
$starts = Application_Model_Schedule::AirtimeTimeToPypoTime($item["starts"]);
|
||||
$data[$starts] = array(
|
||||
'id' => $storedFile->getGunid(),
|
||||
'uri' => $uri,
|
||||
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
|
||||
'fade_out' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_out"]),
|
||||
'cue_in' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_in"]),
|
||||
'cue_out' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
|
||||
'start' => $starts,
|
||||
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["ends"])
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -566,7 +607,6 @@ class Application_Model_Schedule {
|
|||
|
||||
$starts = Application_Model_Schedule::AirtimeTimeToPypoTime($item["starts"]);
|
||||
$medias[$starts] = array(
|
||||
'row_id' => $item["id"],
|
||||
'id' => $storedFile->getGunid(),
|
||||
'uri' => $uri,
|
||||
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
|
||||
|
@ -574,7 +614,6 @@ class Application_Model_Schedule {
|
|||
'fade_cross' => 0,
|
||||
'cue_in' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_in"]),
|
||||
'cue_out' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
|
||||
'export_source' => 'scheduler',
|
||||
'start' => $starts,
|
||||
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["ends"])
|
||||
);
|
||||
|
|
|
@ -56,23 +56,16 @@ except Exception, e:
|
|||
class Global:
|
||||
def __init__(self):
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
self.set_export_source('scheduler')
|
||||
|
||||
def selfcheck(self):
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
return self.api_client.is_server_compatible()
|
||||
|
||||
def set_export_source(self, export_source):
|
||||
self.export_source = export_source
|
||||
self.cache_dir = config["cache_dir"] + self.export_source + '/'
|
||||
self.schedule_file = self.cache_dir + 'schedule.pickle'
|
||||
self.schedule_tracker_file = self.cache_dir + "schedule_tracker.pickle"
|
||||
|
||||
def test_api(self):
|
||||
self.api_client.test()
|
||||
|
||||
"""
|
||||
def check_schedule(self, export_source):
|
||||
def check_schedule(self):
|
||||
logger = logging.getLogger()
|
||||
|
||||
try:
|
||||
|
|
|
@ -39,9 +39,22 @@ class PypoFetch(Thread):
|
|||
def __init__(self, pypoFetch_q, pypoPush_q):
|
||||
Thread.__init__(self)
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
self.set_export_source('scheduler')
|
||||
|
||||
self.fetch_queue = pypoFetch_q
|
||||
self.push_queue = pypoPush_q
|
||||
|
||||
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
||||
logger.debug("Cache dir %s", self.cache_dir)
|
||||
try:
|
||||
if not os.path.exists(dir):
|
||||
logger.debug("Cache dir does not exist. Creating...")
|
||||
os.makedirs(dir)
|
||||
except Exception, e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
|
||||
|
||||
self.schedule_data = []
|
||||
logger = logging.getLogger('fetch')
|
||||
logger.info("PypoFetch: init complete")
|
||||
|
@ -229,15 +242,6 @@ class PypoFetch(Thread):
|
|||
if(status == "true"):
|
||||
self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time))
|
||||
|
||||
|
||||
|
||||
def set_export_source(self, export_source):
|
||||
logger = logging.getLogger('fetch')
|
||||
self.export_source = export_source
|
||||
self.cache_dir = config["cache_dir"] + self.export_source + '/'
|
||||
logger.info("Creating cache directory at %s", self.cache_dir)
|
||||
|
||||
|
||||
def update_liquidsoap_stream_format(self, stream_format):
|
||||
# Push stream metadata to liquidsoap
|
||||
# TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!!
|
||||
|
@ -278,7 +282,7 @@ class PypoFetch(Thread):
|
|||
to the cache dir (Folder-structure: cache/YYYY-MM-DD-hh-mm-ss)
|
||||
- runs the cleanup routine, to get rid of unused cached files
|
||||
"""
|
||||
def process_schedule(self, schedule_data, export_source, bootstrapping):
|
||||
def process_schedule(self, schedule_data, bootstrapping):
|
||||
logger = logging.getLogger('fetch')
|
||||
playlists = schedule_data["playlists"]
|
||||
|
||||
|
@ -294,7 +298,7 @@ class PypoFetch(Thread):
|
|||
self.push_queue.put(scheduled_data)
|
||||
|
||||
# cleanup
|
||||
try: self.cleanup(self.export_source)
|
||||
try: self.cleanup()
|
||||
except Exception, e: logger.error("%s", e)
|
||||
|
||||
"""
|
||||
|
@ -375,7 +379,7 @@ class PypoFetch(Thread):
|
|||
|
||||
fileExt = os.path.splitext(media['uri'])[1]
|
||||
try:
|
||||
dst = "%s%s/%s%s" % (self.cache_dir, pkey, media['id'], fileExt)
|
||||
dst = os.path.join(self.cache_dir, pkey, media['id']+fileExt)
|
||||
|
||||
# download media file
|
||||
self.handle_remote_file(media, dst)
|
||||
|
@ -389,8 +393,8 @@ class PypoFetch(Thread):
|
|||
|
||||
if fsize > 0:
|
||||
pl_entry = \
|
||||
'annotate:export_source="%s",media_id="%s",liq_start_next="%s",liq_fade_in="%s",liq_fade_out="%s",liq_cue_in="%s",liq_cue_out="%s",schedule_table_id="%s":%s' \
|
||||
% (media['export_source'], media['id'], 0, \
|
||||
'annotate:media_id="%s",liq_start_next="%s",liq_fade_in="%s",liq_fade_out="%s",liq_cue_in="%s",liq_cue_out="%s",schedule_table_id="%s":%s' \
|
||||
% (media['id'], 0, \
|
||||
float(media['fade_in']) / 1000, \
|
||||
float(media['fade_out']) / 1000, \
|
||||
float(media['cue_in']), \
|
||||
|
@ -435,7 +439,7 @@ class PypoFetch(Thread):
|
|||
Cleans up folders in cache_dir. Look for modification date older than "now - CACHE_FOR"
|
||||
and deletes them.
|
||||
"""
|
||||
def cleanup(self, export_source):
|
||||
def cleanup(self):
|
||||
logger = logging.getLogger('fetch')
|
||||
|
||||
offset = 3600 * int(config["cache_for"])
|
||||
|
|
|
@ -34,7 +34,6 @@ class PypoPush(Thread):
|
|||
def __init__(self, q):
|
||||
Thread.__init__(self)
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
self.set_export_source('scheduler')
|
||||
self.queue = q
|
||||
|
||||
self.schedule = dict()
|
||||
|
@ -42,11 +41,6 @@ class PypoPush(Thread):
|
|||
|
||||
self.liquidsoap_state_play = True
|
||||
self.push_ahead = 10
|
||||
|
||||
def set_export_source(self, export_source):
|
||||
self.export_source = export_source
|
||||
self.cache_dir = config["cache_dir"] + self.export_source + '/'
|
||||
self.schedule_tracker_file = self.cache_dir + "schedule_tracker.pickle"
|
||||
|
||||
"""
|
||||
The Push Loop - the push loop periodically checks if there is a playlist
|
||||
|
@ -54,7 +48,7 @@ class PypoPush(Thread):
|
|||
If yes, the current liquidsoap playlist gets replaced with the corresponding one,
|
||||
then liquidsoap is asked (via telnet) to reload and immediately play it.
|
||||
"""
|
||||
def push(self, export_source):
|
||||
def push(self):
|
||||
logger = logging.getLogger('push')
|
||||
|
||||
timenow = time.time()
|
||||
|
|
Loading…
Reference in New Issue