コード例 #1
0
ファイル: NowPlaying.php プロジェクト: Lavoaster/PVLive
 /**
  * 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;
 }
コード例 #2
0
ファイル: Station.php プロジェクト: Lavoaster/PVLive
 public static function api($row)
 {
     if ($row instanceof self) {
         $row = $row->toArray();
     }
     $api = array('id' => (int) $row['id'], 'name' => $row['name'], 'shortcode' => self::getStationShortName($row['name']), 'genre' => $row['genre'], 'category' => $row['category'], 'affiliation' => $row['affiliation'], 'image_url' => \PVL\Url::upload($row['image_url']), 'web_url' => $row['web_url'], 'twitter_url' => $row['twitter_url'], 'irc' => $row['irc'], 'sort_order' => (int) $row['weight']);
     if (isset($row['streams'])) {
         $api['streams'] = array();
         foreach ((array) $row['streams'] as $stream) {
             $api['streams'][] = StationStream::api($stream);
             // Set first stream as default, override if a later stream is explicitly default.
             if ($stream['is_default'] || !isset($api['default_stream_id'])) {
                 $api['default_stream_id'] = (int) $stream['id'];
                 $api['stream_url'] = $stream['stream_url'];
             }
         }
     }
     $api['player_url'] = ShortUrl::stationUrl($api['shortcode']);
     if ($row['requests_enabled']) {
         $api['request_url'] = \DF\Url::route(array('module' => 'default', 'controller' => 'station', 'action' => 'request', 'id' => $row['id']));
     } else {
         $api['request_url'] = '';
     }
     return $api;
 }