/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { //Get the youtube ID from the video url $youtubeID = $this->video->getVideoUrl($request->youtubeID); //Return error if link is not valid if ($youtubeID === 'error') { return redirect('/videos/' . $request->video_id . '/edit')->withErrors(['youtubeID' => 'The url is not a youtube video']); } //Get information about the video with valid Youtube ID $video_info = Youtube::getVideoInfo($youtubeID); //Check if the video actually exists if ($video_info == false) { return redirect('/videos/' . $request->video_id . '/edit')->withErrors(['youtubeID' => 'This video does not exist']); } return $next($request); }
/** * Map the video to a new layout * * @param $id * @return array * @throws VideoNotFoundException */ public function mapVideo($id) { $video = Youtube::getVideoInfo($id); if ($video) { return ['status' => 200, 'name' => $video->snippet->title, 'description' => $video->snippet->description, 'link' => 'http://www.youtube.com/watch?v=' . $id]; } else { throw new VideoNotFoundException('The video could not be found.'); } }
/** * Handles new video for saving to the database. * * @param VideosRequest $request * * @return $this|\Illuminate\Http\RedirectResponse */ public function store(VideosRequest $request) { $youtubeID = $this->video->getVideoUrl($request->youtubeID); if ($youtubeID === 'error') { return redirect('/dashboard')->withErrors(['youtubeID' => 'The url is not a youtube video']); } $video_info = Youtube::getVideoInfo($youtubeID); if ($video_info == false) { return redirect('/dashboard')->withErrors(['youtubeID' => 'This video does not exist']); } $data = $request->toArray(); $data['category_id'] = $request->category + 1; $data['user_id'] = Auth::user()->id; $data['youtubeID'] = $youtubeID; $this->video->save($data); return redirect('/dashboard')->with('success', 'video added'); }
public static function getPersonalVideos() { $objVideos = new Videos(); $personal_videos = $objVideos->select('idVideo')->where('status', '=', 1)->orderBy('updated_at', 'desc')->limit(5)->get(); $list_comment = $objVideos->select('idVideo')->orderBy('commentCount', 'desc')->limit(5)->get(); $list_views = $objVideos->select('idVideo')->orderBy('viewCount', 'desc')->limit(5)->get(); $list_id = array(); $list_id_comment = array(); $list_id_views = array(); foreach ($personal_videos as $video) { array_push($list_id, $video->idVideo); } foreach ($list_comment as $video) { array_push($list_id_comment, $video->idVideo); } foreach ($list_views as $video) { array_push($list_id_views, $video->idVideo); } $list_personal_videos = Youtube::getVideoInfo($list_id); $list_comment_videos = Youtube::getVideoInfo($list_id_comment); $list_views_videos = Youtube::getVideoInfo($list_id_views); return array('recent_videos' => $list_personal_videos, 'comment_videos' => $list_comment_videos, 'views_videos' => $list_views_videos); }