Merge branch '1.9.1' of dev.sourcefabric.org:airtime into 1.9.1

This commit is contained in:
James 2011-09-09 16:12:44 -04:00
commit 290a243d60
5 changed files with 22 additions and 54 deletions

View File

@ -439,8 +439,10 @@ class StoredFile {
*/ */
public function getFileUrl() public function getFileUrl()
{ {
global $CC_CONFIG; $serverName = $_SERVER['SERVER_NAME'];
return "http://$CC_CONFIG[baseUrl]:$CC_CONFIG[basePort]/api/get-media/file/".$this->getGunId().".".$this->getFileExtension(); $serverPort = $_SERVER['SERVER_PORT'];
return "http://$serverName:$serverPort/api/get-media/file/".$this->getGunId().".".$this->getFileExtension();
} }
/** /**

View File

@ -62,7 +62,7 @@ python ${SCRIPTPATH}/../python_apps/create-pypo-user.py
set +e set +e
php ${SCRIPTPATH}/include/airtime-install.php $@ php ${SCRIPTPATH}/include/airtime-install.php $@
$result=$? result=$?
if [ "$result" -eq "2" ]; then if [ "$result" -eq "2" ]; then
#We've just finished an upgrade, so let's exit #We've just finished an upgrade, so let's exit
exit 0 exit 0

View File

@ -3,6 +3,7 @@
class Airtime194Upgrade{ class Airtime194Upgrade{
const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg"; const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg";
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
const CONF_PYPO_GRP = "pypo"; const CONF_PYPO_GRP = "pypo";
public static function upgradeLiquidsoapCfgPerms(){ public static function upgradeLiquidsoapCfgPerms(){
@ -10,6 +11,19 @@ class Airtime194Upgrade{
chgrp(self::CONF_FILE_LIQUIDSOAP, self::CONF_PYPO_GRP); chgrp(self::CONF_FILE_LIQUIDSOAP, self::CONF_PYPO_GRP);
} }
public static function InstallAirtimePhpServerCode($phpDir)
{
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
exec("mkdir -p ".$phpDir);
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
} }
}
$values = parse_ini_file(AirtimeIni194::CONF_FILE_AIRTIME, true);
$phpDir = $values['general']['airtime_dir'];
Airtime194Upgrade::InstallAirtimePhpServerCode($phpDir);
Airtime194Upgrade::upgradeLiquidsoapCfgPerms(); Airtime194Upgrade::upgradeLiquidsoapCfgPerms();

View File

@ -41,13 +41,7 @@ class PypoPush(Thread):
self.playlists = dict() self.playlists = dict()
self.stream_metadata = dict() self.stream_metadata = dict()
"""
push_ahead2 MUST be < push_ahead. The difference in these two values
gives the number of seconds of the window of opportunity for the scheduler
to catch when a playlist is to be played.
"""
self.push_ahead = 10 self.push_ahead = 10
self.push_ahead2 = self.push_ahead -5
#toggle between "stop" and "play". Keeps track of the state of #toggle between "stop" and "play". Keeps track of the state of
#liquidsoap #liquidsoap
@ -82,26 +76,17 @@ class PypoPush(Thread):
currently_on_air = False currently_on_air = False
if schedule: if schedule:
playedItems = self.load_schedule_tracker()
timenow = time.time() timenow = time.time()
tcoming = time.localtime(timenow + self.push_ahead) tcoming = time.localtime(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]) 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)
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.localtime(timenow)
str_tnow_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tnow[0], tnow[1], tnow[2], tnow[3], tnow[4], tnow[5]) 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: for pkey in schedule:
plstart = schedule[pkey]['start'][0:19] plstart = schedule[pkey]['start'][0:19]
#plstart = pkey[0:19]
#playedFlag = (pkey in playedItems) and playedItems[pkey].get("played", 0) if str_tnow_s <= plstart and plstart < str_tcoming_s:
playedFlag = False
if plstart == str_tcoming_s or (plstart < str_tcoming_s and plstart > str_tcoming2_s and not playedFlag):
logger.debug('Preparing to push playlist scheduled at: %s', pkey) logger.debug('Preparing to push playlist scheduled at: %s', pkey)
playlist = schedule[pkey] playlist = schedule[pkey]
@ -111,14 +96,6 @@ class PypoPush(Thread):
# force liquidsoap to refresh. # force liquidsoap to refresh.
if (self.push_liquidsoap(pkey, schedule, playlists) == 1): if (self.push_liquidsoap(pkey, schedule, playlists) == 1):
logger.debug("Pushed to liquidsoap, updating 'played' status.") logger.debug("Pushed to liquidsoap, updating 'played' status.")
# Marked the current playlist as 'played' in the schedule tracker
# so it is not called again in the next push loop.
# Write changes back to tracker file.
playedItems[pkey] = playlist
playedItems[pkey]['played'] = 1
schedule_tracker = open(self.schedule_tracker_file, "w")
pickle.dump(playedItems, schedule_tracker)
schedule_tracker.close()
# Call API to update schedule states # Call API to update schedule states
logger.debug("Doing callback to server to update 'played' status.") logger.debug("Doing callback to server to update 'played' status.")
@ -129,8 +106,6 @@ class PypoPush(Thread):
if show_start <= str_tnow_s and str_tnow_s < show_end: if show_start <= str_tnow_s and str_tnow_s < show_end:
currently_on_air = True currently_on_air = True
else:
pass
if not currently_on_air and self.liquidsoap_state_play: if not currently_on_air and self.liquidsoap_state_play:
logger.debug('Notifying Liquidsoap to stop playback.') logger.debug('Notifying Liquidsoap to stop playback.')
@ -202,29 +177,6 @@ class PypoPush(Thread):
status = 0 status = 0
return status return status
def load_schedule_tracker(self):
logger = logging.getLogger('push')
playedItems = dict()
# create the file if it doesnt exist
if (not os.path.exists(self.schedule_tracker_file)):
try:
logger.debug('creating file ' + self.schedule_tracker_file)
schedule_tracker = open(self.schedule_tracker_file, 'w')
pickle.dump(playedItems, schedule_tracker)
schedule_tracker.close()
except Exception, e:
logger.error('Error creating schedule tracker file: %s', e)
else:
try:
schedule_tracker = open(self.schedule_tracker_file, "r")
playedItems = pickle.load(schedule_tracker)
schedule_tracker.close()
except Exception, e:
logger.error('Unable to load schedule tracker file: %s', e)
return playedItems
def run(self): def run(self):
loops = 0 loops = 0
heartbeat_period = math.floor(30/PUSH_INTERVAL) heartbeat_period = math.floor(30/PUSH_INTERVAL)