Beispiel #1
0
 public function editAction()
 {
     if ($this->station->category == 'video') {
         $form_config = $this->current_module_config->forms->video_stream;
     } else {
         $form_config = $this->current_module_config->forms->radio_stream;
     }
     $form = new \DF\Form($form_config);
     if ($this->hasParam('id')) {
         $record = StationStream::getRepository()->findOneBy(array('id' => $this->getParam('id'), 'station_id' => $this->station->id));
         $form->setDefaults($record->toArray());
     }
     if (!empty($_POST) && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$record instanceof StationStream) {
             $record = new StationStream();
             $record->station = $this->station;
         }
         $record->fromArray($data);
         $record->save();
         // Ensure at least one stream is default.
         $this->station->checkDefaultStream();
         // Clear station cache.
         \DF\Cache::remove('stations');
         // Immediately load "Now Playing" data for the added/updated stream.
         if ($data['is_active'] == 0) {
             $record->save();
             $this->alert('<b>Stream updated, but is currently inactive.</b><br>The system will not retrieve Now Playing data about this stream until it is activated.', 'red');
         } elseif ($this->station->category == 'video') {
             $np = \PVL\NowPlaying::processVideoStream($record, $this->station, true);
             $record->save();
             if ($np['meta']['status'] == 'online') {
                 $this->alert('<b>Stream updated, and currently showing as online.</b>', 'green');
             } else {
                 $this->alert('<b>Stream updated, but is currently offline.</b>', 'red');
             }
         } else {
             $np = \PVL\NowPlaying::processAudioStream($record, $this->station, true);
             $record->save();
             if ($np['status'] != 'offline') {
                 $song = $np['current_song'];
                 $this->alert('<b>Stream updated and successfully connected.</b><br>The currently playing song is reporting as "' . $song['title'] . '" by "' . $song['artist'] . '" with ' . $np['listeners']['current'] . ' tuned in.', 'green');
             } else {
                 $this->alert('<b>Stream updated, but is currently offline.</b><br>The system could not retrieve now-playing information about this stream. Verify that the station is online and the URLs are correct.', 'red');
             }
         }
         $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
         return;
     }
     $title = ($this->hasParam('id') ? 'Edit' : 'Add') . ' Station Stream';
     $this->renderForm($form, 'edit', $title);
 }
Beispiel #2
0
 public static function syncNowplaying($force = false)
 {
     self::initSync(60);
     // Prevent nowplaying from running on top of itself.
     $last_start = Settings::getSetting('nowplaying_last_started', 0);
     $last_end = Settings::getSetting('nowplaying_last_run', 0);
     if ($last_start > $last_end && $last_start >= time() - 300 && !$force) {
         return;
     }
     // Sync schedules.
     Settings::setSetting('nowplaying_last_started', time());
     // Run different tasks for different "segments" of now playing data.
     if (!defined('NOWPLAYING_SEGMENT')) {
         define('NOWPLAYING_SEGMENT', 1);
     }
     // Run Now Playing data for radio streams.
     Debug::runTimer('Run NowPlaying update', function () {
         NowPlaying::generate();
     });
     Settings::setSetting('nowplaying_last_run', time());
 }