public function postEdit() { $videoId = $this->getInt('id'); $postData = $this->request()->postVariables(); if (isset($postData['caption'])) { foreach ($postData['caption'] as $captionId => $captionData) { $caption = new VideoCaption($captionId); $caption->startSecond = $captionData['start']; $caption->endSecond = $captionData['end']; $caption->text = $captionData['text']; $caption->saveChanges(); } } if (isset($postData['_caption'])) { foreach ($postData['_caption'] as $captionData) { $caption = new VideoCaption(); $caption->videoId = $videoId; $caption->startSecond = $captionData['start']; $caption->endSecond = $captionData['end']; $caption->text = $captionData['text']; $caption->saveChanges(); } } Redirect::to('/admin/video/' . $videoId . '/caption/' . $videoId . '/edit')->now(); }
public static function create($videoId, $text, $api = Captionify::API_JTALK) { //this might take up to 2 mins to finish, so let make that provision set_time_limit(120); //we want to always start afresh when captionifying text //so delete all existing caption before we start $captions = VideoCaption::collection(['video_id' => $videoId]); foreach ($captions as $caption) { $caption->delete(); } $text = str_replace('. ', "\n", $text); $sentences = explode("\n", $text); $result = array(); $lastEnd = 0; foreach ($sentences as $sentence) { switch ($api) { case self::API_TTSAPI: $caption = self::_jTalkCaptionify($sentence, $lastEnd, 0); break; case self::API_JTALK: default: $caption = self::_ttsApiCaptionify($sentence, $lastEnd, 0); break; } if ($caption) { $lastEnd += $caption['duration']; $result[] = $caption; } } foreach ($result as $captionData) { $caption = new VideoCaption(); $caption->videoId = $videoId; $caption->startSecond = $captionData['start']; $caption->endSecond = $captionData['end']; $caption->text = $captionData['text']; $caption->saveChanges(); } }
/** * Add videos * * @return $this */ protected function _addVideos() { echo 'Adding Videos: '; $count = 0; $captionCount = 0; /** @var Category[] $categories */ $categories = Category::collection(); foreach ($categories as $category) { if (rand(1, 3)) { $videoTitles = $this->_getTitleArray('Video', rand(1, 3)); foreach ($videoTitles as $videoTitle) { $video = new Video(); $video->title = $videoTitle; $video->slug = Strings::urlize($videoTitle); $video->subTitle = $this->_getExampleContent(rand(3, 15)); $video->categoryId = $category->id(); $video->url = 'http://content.bitsontherun.com/videos/lWMJeVvV-364767.mp4'; $video->saveChanges(); // Add Annotations $videoCaptionCount = rand(20, 30); $i = 1; $lastSecond = 0; do { $caption = new VideoCaption(); $caption->videoId = $video->id(); $caption->text = $this->_getExampleContent(rand(2, 6)); $caption->startSecond = $lastSecond; $lastSecond += rand(3, 6); $caption->endSecond = $lastSecond; $caption->saveChanges(); $captionCount++; $i++; } while ($i <= $videoCaptionCount); $count++; } } } echo sprintf('%d (%d Total Captions)%s', $count, $captionCount, PHP_EOL); return $this; }