Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
38256de606
22 changed files with 199 additions and 184 deletions
|
@ -622,7 +622,9 @@ class ObpApiClient():
|
|||
|
||||
return obp_version
|
||||
|
||||
|
||||
"""
|
||||
NOTE: The server currently ignores start and end parameters we send to it.
|
||||
"""
|
||||
def get_schedule(self, start=None, end=None):
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
@ -630,13 +632,12 @@ class ObpApiClient():
|
|||
calculate start/end time range (format: YYYY-DD-MM-hh-mm-ss,YYYY-DD-MM-hh-mm-ss)
|
||||
(seconds are ignored, just here for consistency)
|
||||
"""
|
||||
tnow = time.localtime(time.time())
|
||||
if (not start):
|
||||
tstart = time.localtime(time.time() - 3600 * int(self.config["cache_for"]))
|
||||
tstart = time.gmtime(time.time() - 3600 * int(self.config["cache_for"]))
|
||||
start = "%04d-%02d-%02d-%02d-%02d" % (tstart[0], tstart[1], tstart[2], tstart[3], tstart[4])
|
||||
|
||||
if (not end):
|
||||
tend = time.localtime(time.time() + 3600 * int(self.config["prepare_ahead"]))
|
||||
tend = time.gmtime(time.time() + 3600 * int(self.config["prepare_ahead"]))
|
||||
end = "%04d-%02d-%02d-%02d-%02d" % (tend[0], tend[1], tend[2], tend[3], tend[4])
|
||||
|
||||
range = {}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
import calendar
|
||||
import logging
|
||||
import logging.config
|
||||
import shutil
|
||||
|
@ -53,12 +54,9 @@ Hopefully there is a better way to do this.
|
|||
|
||||
if(command == 'update_schedule'):
|
||||
SCHEDULE_PUSH_MSG = m['schedule']
|
||||
elif (command == 'update_timezone'):
|
||||
logger.info("Setting timezone to %s", m['timezone'])
|
||||
os.environ['TZ'] = m['timezone']
|
||||
time.tzset()
|
||||
elif (command == 'update_stream_setting'):
|
||||
logger.info("Updating stream setting: %s", m['setting'])
|
||||
|
||||
# ACK the message to take it off the queue
|
||||
message.ack()"""
|
||||
|
||||
|
@ -104,10 +102,6 @@ class PypoFetch(Thread):
|
|||
if(command == 'update_schedule'):
|
||||
self.schedule_data = m['schedule']
|
||||
self.process_schedule(self.schedule_data, "scheduler", False)
|
||||
elif (command == 'update_timezone'):
|
||||
logger.info("Setting timezone to %s", m['timezone'])
|
||||
os.environ['TZ'] = m['timezone']
|
||||
time.tzset()
|
||||
elif (command == 'update_stream_setting'):
|
||||
logger.info("Updating stream setting...")
|
||||
self.regenerateLiquidsoapConf(m['setting'])
|
||||
|
@ -212,20 +206,6 @@ class PypoFetch(Thread):
|
|||
self.cache_dir = config["cache_dir"] + self.export_source + '/'
|
||||
logger.info("Creating cache directory at %s", self.cache_dir)
|
||||
|
||||
def check_matching_timezones(self, server_timezone):
|
||||
logger = logging.getLogger('fetch')
|
||||
|
||||
process = Popen(["date", "+%z"], stdout=PIPE)
|
||||
pypo_timezone = (process.communicate()[0]).strip(' \r\n\t')
|
||||
|
||||
if server_timezone != pypo_timezone:
|
||||
logger.error("ERROR: Airtime server and pypo timezone offsets do not match. Audio playback will not start when expected!!!")
|
||||
logger.error(" * Server timezone offset: %s", server_timezone)
|
||||
logger.error(" * Pypo timezone offset: %s", pypo_timezone)
|
||||
logger.error(" * To fix this, you need to set the 'date.timezone' value in your php.ini file and restart apache.")
|
||||
logger.error(" * See this page for more info (v1.7): http://wiki.sourcefabric.org/x/BQBF")
|
||||
logger.error(" * and also the 'FAQ and Support' page underneath it.")
|
||||
|
||||
"""
|
||||
def get_currently_scheduled(self, playlistsOrMedias, str_tnow_s):
|
||||
for key in playlistsOrMedias:
|
||||
|
@ -274,12 +254,6 @@ class PypoFetch(Thread):
|
|||
logger = logging.getLogger('fetch')
|
||||
playlists = schedule_data["playlists"]
|
||||
|
||||
#if bootstrapping:
|
||||
#TODO: possible allow prepare_playlists to handle this.
|
||||
#self.handle_shows_currently_scheduled(playlists)
|
||||
|
||||
self.check_matching_timezones(schedule_data["server_timezone"])
|
||||
|
||||
# Push stream metadata to liquidsoap
|
||||
# TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!!
|
||||
stream_metadata = schedule_data['stream_metadata']
|
||||
|
@ -465,7 +439,7 @@ class PypoFetch(Thread):
|
|||
for r, d, f in os.walk(self.cache_dir):
|
||||
for dir in d:
|
||||
try:
|
||||
timestamp = time.mktime(time.strptime(dir, "%Y-%m-%d-%H-%M-%S"))
|
||||
timestamp = calendar.timegm(time.strptime(dir, "%Y-%m-%d-%H-%M-%S"))
|
||||
if (now - timestamp) > offset:
|
||||
try:
|
||||
logger.debug('trying to remove %s - timestamp: %s', os.path.join(r, dir), timestamp)
|
||||
|
|
|
@ -85,23 +85,19 @@ class PypoPush(Thread):
|
|||
playedItems = self.load_schedule_tracker()
|
||||
|
||||
timenow = time.time()
|
||||
tcoming = time.localtime(timenow + self.push_ahead)
|
||||
tcoming = time.gmtime(timenow + self.push_ahead)
|
||||
str_tcoming_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tcoming[0], tcoming[1], tcoming[2], tcoming[3], tcoming[4], tcoming[5])
|
||||
|
||||
tcoming2 = time.localtime(timenow + self.push_ahead2)
|
||||
tcoming2 = time.gmtime(timenow + self.push_ahead2)
|
||||
str_tcoming2_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tcoming2[0], tcoming2[1], tcoming2[2], tcoming2[3], tcoming2[4], tcoming2[5])
|
||||
|
||||
tnow = time.localtime(timenow)
|
||||
tnow = time.gmtime(timenow)
|
||||
str_tnow_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tnow[0], tnow[1], tnow[2], tnow[3], tnow[4], tnow[5])
|
||||
|
||||
for pkey in schedule:
|
||||
plstart = schedule[pkey]['start'][0:19]
|
||||
#plstart = pkey[0:19]
|
||||
|
||||
#playedFlag = (pkey in playedItems) and playedItems[pkey].get("played", 0)
|
||||
playedFlag = False
|
||||
|
||||
if plstart == str_tcoming_s or (plstart < str_tcoming_s and plstart > str_tcoming2_s and not playedFlag):
|
||||
if plstart == str_tcoming_s or (plstart < str_tcoming_s and plstart > str_tcoming2_s):
|
||||
logger.debug('Preparing to push playlist scheduled at: %s', pkey)
|
||||
playlist = schedule[pkey]
|
||||
|
||||
|
@ -156,7 +152,7 @@ class PypoPush(Thread):
|
|||
#mktime takes a time_struct and returns a floating point
|
||||
#gmtime Convert a time expressed in seconds since the epoch to a struct_time in UTC
|
||||
#mktime: expresses the time in local time, not UTC. It returns a floating point number, for compatibility with time().
|
||||
epoch_start = calendar.timegm(time.gmtime(time.mktime(time.strptime(pkey, '%Y-%m-%d-%H-%M-%S'))))
|
||||
epoch_start = calendar.timegm(time.strptime(pkey, '%Y-%m-%d-%H-%M-%S'))
|
||||
|
||||
#Return the time as a floating point number expressed in seconds since the epoch, in UTC.
|
||||
epoch_now = time.time()
|
||||
|
|
|
@ -42,12 +42,14 @@ except Exception, e:
|
|||
sys.exit()
|
||||
|
||||
def getDateTimeObj(time):
|
||||
|
||||
timeinfo = time.split(" ")
|
||||
date = timeinfo[0].split("-")
|
||||
time = timeinfo[1].split(":")
|
||||
|
||||
date = map(int, date)
|
||||
time = map(int, time)
|
||||
|
||||
return datetime.datetime(int(date[0]), int(date[1]), int(date[2]), int(time[0]), int(time[1]), int(time[2]))
|
||||
return datetime.datetime(date[0], date[1], date[2], time[0], time[1], time[2], 0, None)
|
||||
|
||||
class ShowRecorder(Thread):
|
||||
|
||||
|
@ -168,7 +170,7 @@ class CommandListener(Thread):
|
|||
self.logger = logging.getLogger('root')
|
||||
self.sr = None
|
||||
self.current_schedule = {}
|
||||
self.shows_to_record = []
|
||||
self.shows_to_record = {}
|
||||
self.time_till_next_show = 3600
|
||||
self.logger.info("RecorderFetch: init complete")
|
||||
|
||||
|
@ -211,9 +213,8 @@ class CommandListener(Thread):
|
|||
show_starts = getDateTimeObj(show[u'starts'])
|
||||
show_end = getDateTimeObj(show[u'ends'])
|
||||
time_delta = show_end - show_starts
|
||||
|
||||
|
||||
self.shows_to_record[show[u'starts']] = [time_delta, show[u'instance_id'], show[u'name']]
|
||||
|
||||
delta = self.get_time_till_next_show()
|
||||
# awake at least 5 seconds prior to the show start
|
||||
self.time_till_next_show = delta - 5
|
||||
|
@ -222,7 +223,7 @@ class CommandListener(Thread):
|
|||
|
||||
def get_time_till_next_show(self):
|
||||
if len(self.shows_to_record) != 0:
|
||||
tnow = datetime.datetime.now()
|
||||
tnow = datetime.datetime.utcnow()
|
||||
sorted_show_keys = sorted(self.shows_to_record.keys())
|
||||
|
||||
start_time = sorted_show_keys[0]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue