diff --git a/airtime_mvc/application/models/DateHelper.php b/airtime_mvc/application/models/DateHelper.php index d8f44a3c5..bc7b21a86 100644 --- a/airtime_mvc/application/models/DateHelper.php +++ b/airtime_mvc/application/models/DateHelper.php @@ -127,5 +127,35 @@ class DateHelper $explode = explode(" ", $p_timestamp); return $explode[1]; } + + /* Given a track length in the format HH:MM:SS.mm, we want to + * convert this to seconds. This is useful for Liquidsoap which + * likes input parameters give in seconds. + * For example, 00:06:31.444, should be converted to 391.444 seconds + * @param int $p_time + * The time interval in format HH:MM:SS.mm we wish to + * convert to seconds. + * @return int + * The input parameter converted to seconds. + */ + public static function calculateLengthInSeconds($p_time){ + + if (2 !== substr_count($p_time, ":")){ + return FALSE; + } + + if (1 === substr_count($p_time, ".")){ + list($hhmmss, $ms) = explode(".", $p_time); + } else { + $hhmmss = $p_time; + $ms = 0; + } + + list($hours, $minutes, $seconds) = explode(":", $hhmmss); + + $totalSeconds = $hours*3600 + $minutes*60 + $seconds + $ms/1000; + + return $totalSeconds; + } } diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 5aadbdf78..d4750fb09 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -697,11 +697,6 @@ class Schedule { $storedFile = StoredFile::Recall($item["file_id"]); $uri = $storedFile->getFileUrl(); - // For pypo, a cueout of zero means no cueout - $cueOut = "0"; - if (Schedule::TimeDiff($item["cue_out"], $item["clip_length"]) > 0.001) { - $cueOut = Schedule::WallTimeToMillisecs($item["cue_out"]); - } $starts = Schedule::AirtimeTimeToPypoTime($item["starts"]); $medias[$starts] = array( 'row_id' => $item["id"], @@ -710,8 +705,8 @@ class Schedule { 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), 'fade_cross' => 0, - 'cue_in' => Schedule::WallTimeToMillisecs($item["cue_in"]), - 'cue_out' => $cueOut, + 'cue_in' => DateHelper::CalculateLengthInSeconds($item["cue_in"]), + 'cue_out' => DateHelper::CalculateLengthInSeconds($item["cue_out"]), 'export_source' => 'scheduler', 'start' => $starts, 'end' => Schedule::AirtimeTimeToPypoTime($item["ends"]) diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 7006780ce..9c7fc9d84 100755 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -260,7 +260,7 @@ class PypoFetch(Thread): delta = dtnow - media_start #we get a TimeDelta object from this operation logger.info("Starting media item at %d second point", delta.seconds) - media['cue_in'] = delta.seconds + 10 #TODO is cue_in in seconds? + media['cue_in'] = delta.seconds + 10 td = timedelta(seconds=10) playlist['start'] = (dtnow + td).strftime('%Y-%m-%d-%H-%M-%S') logger.info("Crash detected, setting playlist to restart at %s", (dtnow + td).strftime('%Y-%m-%d-%H-%M-%S'))