Example #1
0
 /**
  * Process a single video stream's NowPlaying info.
  *
  * @param StationStream $stream
  * @param Station $station
  * @return array Structured NowPlaying Data
  */
 public static function processVideoStream(StationStream $stream, Station $station, $force = false)
 {
     $current_np_data = (array) $stream->nowplaying_data;
     if (!$force && NOWPLAYING_SEGMENT % 2 == 0 && !empty($current_np_data)) {
         return $current_np_data;
     }
     // Process stream.
     $custom_class = Station::getStationClassName($station->name);
     $custom_adapter = '\\PVL\\VideoAdapter\\' . $custom_class;
     $np = StationStream::api($stream);
     if (class_exists($custom_adapter)) {
         $np_adapter = new $custom_adapter($stream, $station);
         $stream_np = $np_adapter->process();
     } else {
         $adapters = array(new \PVL\VideoAdapter\Livestream($stream, $station), new \PVL\VideoAdapter\TwitchTv($stream, $station), new \PVL\VideoAdapter\UStream($stream, $station), new \PVL\VideoAdapter\StreamUp($stream, $station));
         foreach ($adapters as $np_adapter) {
             if ($np_adapter->canHandle()) {
                 $stream_np = $np_adapter->process();
                 break;
             }
         }
     }
     if (!empty($stream_np)) {
         $np = array_merge($np, $stream_np);
         $np['status'] = isset($np['meta']['status']) ? $np['meta']['status'] : 'offline';
         Debug::log('Adapter Class: ' . get_class($np_adapter));
         Debug::print_r($np);
     } else {
         $np['on_air'] = array('text' => 'Stream Offline');
         $np['meta'] = array('status' => 'offline', 'listeners' => 0);
         $np['status'] = 'offline';
     }
     $stream->nowplaying_data = $np;
     return $np;
 }