Exemplo n.º 1
0
 public function notifyMediaItemStartPlayAction()
 {
     $media_id = $this->_getParam("media_id");
     Logging::debug("Received notification of new media item start: {$media_id}");
     Application_Model_Schedule::UpdateMediaPlayedStatus($media_id);
     $historyService = new Application_Service_HistoryService();
     $historyService->insertPlayedItem($media_id);
     //set a 'last played' timestamp for media item
     //needed for smart blocks
     try {
         $mediaType = Application_Model_Schedule::GetType($media_id);
         if ($mediaType == 'file') {
             $file_id = Application_Model_Schedule::GetFileId($media_id);
             if (!is_null($file_id)) {
                 //we are dealing with a file not a stream
                 $file = Application_Model_StoredFile::RecallById($file_id);
                 $now = new DateTime("now", new DateTimeZone("UTC"));
                 $file->setLastPlayedTime($now);
             }
         } else {
             // webstream
             $stream_id = Application_Model_Schedule::GetStreamId($media_id);
             if (!is_null($stream_id)) {
                 $webStream = new Application_Model_Webstream($stream_id);
                 $now = new DateTime("now", new DateTimeZone("UTC"));
                 $webStream->setLastPlayed($now);
             }
         }
     } catch (Exception $e) {
         Logging::info($e);
     }
     $this->_helper->json->sendJson(array("status" => 1, "message" => ""));
 }
 public function saveAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam("id");
     $parameters = array();
     foreach (array('id', 'length', 'name', 'description', 'url') as $p) {
         $parameters[$p] = trim($request->getParam($p));
     }
     if (!$this->isAuthorized($id)) {
         header("Status: 401 Not Authorized");
         return;
     }
     list($analysis, $mime, $mediaUrl, $di) = Application_Model_Webstream::analyzeFormData($parameters);
     try {
         if (Application_Model_Webstream::isValid($analysis)) {
             $streamId = Application_Model_Webstream::save($parameters, $mime, $mediaUrl, $di);
             Application_Model_Library::changePlaylist($streamId, "stream");
             $this->view->statusMessage = "<div class='success'>" . _("Webstream saved.") . "</div>";
             $this->view->streamId = $streamId;
             $this->view->length = $di->format("%Hh %Im");
         } else {
             throw new Exception("isValid returned false");
         }
     } catch (Exception $e) {
         Logging::debug($e->getMessage());
         $this->view->statusMessage = "<div class='errors'>" . _("Invalid form values.") . "</div>";
         $this->view->streamId = -1;
         $this->view->analysis = $analysis;
     }
 }
Exemplo n.º 3
0
 public function notifyMediaItemStartPlayAction()
 {
     // disable the view and the layout
     $this->view->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $media_id = $this->_getParam("media_id");
     Logging::debug("Received notification of new media item start: {$media_id}");
     Application_Model_Schedule::UpdateMediaPlayedStatus($media_id);
     //set a 'last played' timestamp for media item
     //needed for smart blocks
     try {
         $mediaType = Application_Model_Schedule::GetType($media_id);
         if ($mediaType == 'file') {
             $file_id = Application_Model_Schedule::GetFileId($media_id);
             if (!is_null($file_id)) {
                 //we are dealing with a file not a stream
                 $file = Application_Model_StoredFile::Recall($file_id);
                 $now = new DateTime("now", new DateTimeZone("UTC"));
                 $file->setLastPlayedTime($now);
             }
         } else {
             // webstream
             $stream_id = Application_Model_Schedule::GetStreamId($media_id);
             if (!is_null($stream_id)) {
                 $webStream = new Application_Model_Webstream($stream_id);
                 $now = new DateTime("now", new DateTimeZone("UTC"));
                 $webStream->setLastPlayed($now);
             }
         }
     } catch (Exception $e) {
         Logging::info($e);
     }
     echo json_encode(array("status" => 1, "message" => ""));
 }
Exemplo n.º 4
0
 public function getFileMetadataAction()
 {
     $id = $this->_getParam('id');
     $type = $this->_getParam('type');
     try {
         if ($type == "audioclip") {
             $file = Application_Model_StoredFile::Recall($id);
             $this->view->type = $type;
             $md = $file->getMetadata();
             foreach ($md as $key => $value) {
                 if ($key == 'MDATA_KEY_DIRECTORY') {
                     $musicDir = Application_Model_MusicDir::getDirByPK($value);
                     $md['MDATA_KEY_FILEPATH'] = Application_Common_OsPath::join($musicDir->getDirectory(), $md['MDATA_KEY_FILEPATH']);
                 }
             }
             $formatter = new SamplerateFormatter($md["MDATA_KEY_SAMPLERATE"]);
             $md["MDATA_KEY_SAMPLERATE"] = $formatter->format();
             $formatter = new BitrateFormatter($md["MDATA_KEY_BITRATE"]);
             $md["MDATA_KEY_BITRATE"] = $formatter->format();
             $formatter = new LengthFormatter($md["MDATA_KEY_DURATION"]);
             $md["MDATA_KEY_DURATION"] = $formatter->format();
             $this->view->md = $md;
         } elseif ($type == "playlist") {
             $file = new Application_Model_Playlist($id);
             $this->view->type = $type;
             $md = $file->getAllPLMetaData();
             $formatter = new LengthFormatter($md["dcterms:extent"]);
             $md["dcterms:extent"] = $formatter->format();
             $this->view->md = $md;
             $this->view->contents = $file->getContents();
         } elseif ($type == "block") {
             $block = new Application_Model_Block($id);
             $this->view->type = $type;
             $md = $block->getAllPLMetaData();
             $formatter = new LengthFormatter($md["dcterms:extent"]);
             $md["dcterms:extent"] = $formatter->format();
             $this->view->md = $md;
             if ($block->isStatic()) {
                 $this->view->blType = 'Static';
                 $this->view->contents = $block->getContents();
             } else {
                 $this->view->blType = 'Dynamic';
                 $this->view->contents = $block->getCriteria();
             }
             $this->view->block = $block;
         } elseif ($type == "stream") {
             $webstream = CcWebstreamQuery::create()->findPK($id);
             $ws = new Application_Model_Webstream($webstream);
             $md = $ws->getMetadata();
             $this->view->md = $md;
             $this->view->type = $type;
         }
     } catch (Exception $e) {
         Logging::info($e->getMessage());
     }
 }