Live now playing info
This commit is contained in:
@@ -246,6 +246,14 @@ if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$
|
||||
return response()->json($program);
|
||||
}
|
||||
|
||||
|
||||
private function getTrack($next = false) {
|
||||
$prefix = $next ? "next" : "current";
|
||||
$data = app('db')->select("SELECT {$prefix}_start AS start, {$prefix}_itemcode AS itemCode, {$prefix}_title AS title, {$prefix}_artist AS artist, {$prefix}_duration AS duration FROM `now_playing`");
|
||||
|
||||
return new \Model\Track($data[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Programmas nu en straks (24 uur vooruit)
|
||||
*/
|
||||
@@ -253,7 +261,23 @@ if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$
|
||||
$start = new \DateTimeImmutable('now');
|
||||
$einde = new \DateTimeImmutable('now + 1 second');
|
||||
$schema = $this->createSchedule($start, $einde);
|
||||
return response()->json(['current' => ['program' => true, 'name' => $schema['schedule'][0]['program']->name]]);
|
||||
$program = $schema['schedule'][0]['program'];
|
||||
if($program->nonstop) {
|
||||
$current = $this->getTrack();
|
||||
$next = $this->getTrack(/* next: */ true);
|
||||
$current->ends($next->start);
|
||||
if($current->isLayout() || $current->secondsRemaining() < 0) {
|
||||
if($next->isLayout()) {
|
||||
return response()->json(['inProgram' => true, 'current' => $program->name]);
|
||||
}
|
||||
|
||||
$current = $next;
|
||||
}
|
||||
|
||||
return response()->json(['inProgram' => false, 'current' => $current]);
|
||||
} else {
|
||||
return response()->json(['inProgram' => true, 'current' => $program->name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
52
common/classes/Track.php
Normal file
52
common/classes/Track.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Track extends Model {
|
||||
public $start;
|
||||
public $itemCode;
|
||||
public $title;
|
||||
public $artist;
|
||||
public $duration;
|
||||
public $ends;
|
||||
|
||||
public function __construct($data) {
|
||||
parent::__construct($data);
|
||||
parent::ConvertToDateTime($this->start);
|
||||
parent::ConvertToDateTime($this->ends);
|
||||
}
|
||||
|
||||
private static $IDENTS = ['NIEUWSOPEN ' => 'Nieuws', 'ANWB' => 'Verkeersinformatie', 'REGIO' => 'Regionieuws', 'CB' => 'Reclame'];
|
||||
|
||||
public function isLayout() {
|
||||
if(strlen($this->itemCode) > 0 && ($this->itemCode[0] == 'V')) {
|
||||
foreach(self::$IDENTS as $ident => $display) {
|
||||
if(substr($this->itemCode, 0, strlen($ident)) == $ident || substr($this->title, 0, strlen($ident)) == $ident) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function ends($ends = null) {
|
||||
$this->ends = $ends;
|
||||
}
|
||||
|
||||
public function secondsRemaining() {
|
||||
return ($this->ends) ? ($this->ends->getTimestamp() - time()) : -1;
|
||||
}
|
||||
|
||||
public function display() {
|
||||
foreach(self::$IDENTS as $ident => $display) {
|
||||
if(substr($this->itemCode, 0, strlen($ident)) == $ident || substr($this->title, 0, strlen($ident)) == $ident) {
|
||||
return $display;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->artist . ($this->artist ? ' - ' : '') . $this->title;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user