Merge branch 'cc-3336-refactor-pypo' of dev.sourcefabric.org:airtime into cc-3336-refactor-pypo
Conflicts: airtime_mvc/application/models/Schedule.php python_apps/pypo/pypofetch.py python_apps/pypo/pypopush.py
This commit is contained in:
commit
497715df44
|
@ -418,9 +418,7 @@ class Application_Model_Schedule {
|
|||
* @return array
|
||||
* Returns null if nothing found
|
||||
*/
|
||||
|
||||
public static function GetItems($p_currentDateTime, $p_toDateTime)
|
||||
{
|
||||
public static function GetItems($p_currentDateTime, $p_toDateTime) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$rows = array();
|
||||
|
||||
|
@ -444,20 +442,6 @@ 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){
|
||||
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
|
|
@ -39,7 +39,6 @@ class PypoFetch(Thread):
|
|||
def __init__(self, pypoFetch_q, pypoPush_q):
|
||||
Thread.__init__(self)
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
|
||||
self.fetch_queue = pypoFetch_q
|
||||
self.push_queue = pypoPush_q
|
||||
|
||||
|
@ -47,6 +46,7 @@ class PypoFetch(Thread):
|
|||
|
||||
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
||||
logger.debug("Cache dir %s", self.cache_dir)
|
||||
|
||||
try:
|
||||
if not os.path.isdir(dir):
|
||||
"""
|
||||
|
@ -210,7 +210,8 @@ class PypoFetch(Thread):
|
|||
else:
|
||||
self.logger.info("No change detected in setting...")
|
||||
self.update_liquidsoap_connection_status()
|
||||
"""
|
||||
def update_liquidsoap_connection_status(self):
|
||||
"""
|
||||
updates the status of liquidsoap connection to the streaming server
|
||||
This fucntion updates the bootup time variable in liquidsoap script
|
||||
"""
|
||||
|
@ -280,10 +281,8 @@ 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, bootstrapping):
|
||||
|
||||
def process_schedule(self, schedule_data, bootstrapping):
|
||||
self.logger.debug(schedule_data)
|
||||
|
||||
media = schedule_data["media"]
|
||||
|
||||
# Download all the media and put playlists in liquidsoap "annotate" format
|
||||
|
@ -292,7 +291,6 @@ class PypoFetch(Thread):
|
|||
except Exception, e: self.logger.error("%s", e)
|
||||
|
||||
# Send the data to pypo-push
|
||||
|
||||
self.logger.debug("Pushing to pypo-push: "+ str(media))
|
||||
self.push_queue.put(media)
|
||||
|
||||
|
|
|
@ -41,13 +41,13 @@ class PypoPush(Thread):
|
|||
self.liquidsoap_state_play = True
|
||||
self.push_ahead = 30
|
||||
|
||||
"""
|
||||
The Push Loop - the push loop periodically checks if there is a playlist
|
||||
that should be scheduled at the current time.
|
||||
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):
|
||||
"""
|
||||
The Push Loop - the push loop periodically checks if there is a playlist
|
||||
that should be scheduled at the current time.
|
||||
If yes, the current liquidsoap playlist gets replaced with the corresponding one,
|
||||
then liquidsoap is asked (via telnet) to reload and immediately play it.
|
||||
"""
|
||||
logger = logging.getLogger('push')
|
||||
|
||||
timenow = time.time()
|
||||
|
@ -89,6 +89,11 @@ class PypoPush(Thread):
|
|||
self.api_client.notify_scheduled_item_start_playing(pkey, schedule)
|
||||
|
||||
def push_to_liquidsoap(self, media_item):
|
||||
"""
|
||||
This function looks at the media item, and either pushes it to the Liquidsoap
|
||||
queue immediately, or if the queue is empty - waits until the start time of the
|
||||
media item before pushing it.
|
||||
"""
|
||||
try:
|
||||
if media_item["starts"] == self.last_end_time:
|
||||
"""
|
||||
|
@ -113,6 +118,12 @@ class PypoPush(Thread):
|
|||
return True
|
||||
|
||||
def sleep_until_start(media_item):
|
||||
"""
|
||||
The purpose of this function is to look at the difference between
|
||||
"now" and when the media_item starts, and sleep for that period of time.
|
||||
After waking from sleep, this function returns.
|
||||
"""
|
||||
|
||||
mi_start = media_item['start'][0:19]
|
||||
|
||||
#strptime returns struct_time in local time
|
||||
|
@ -133,6 +144,12 @@ class PypoPush(Thread):
|
|||
time.sleep(sleep_time)
|
||||
|
||||
def telnet_to_liquidsoap(media_item):
|
||||
"""
|
||||
telnets to liquidsoap and pushes the media_item to its queue. Push the
|
||||
show name of every media_item as well, just to keep Liquidsoap up-to-date
|
||||
about which show is playing.
|
||||
"""
|
||||
|
||||
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||
|
||||
#tn.write(("vars.pypo_data %s\n"%liquidsoap_data["schedule_id"]).encode('utf-8'))
|
||||
|
|
Loading…
Reference in New Issue