示例#1
3
 /**
  * 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);
 }
示例#2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $keyword = $this->argument('keyword');
     $channel = Yt::getChannelByName('allocine');
     if (!empty($channel)) {
         $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
         $collection = new \MongoDB\Collection($manager, 'laravel.stats');
         $collection->deleteMany([]);
         $collection = new \MongoDB\Collection($manager, 'laravel.stats');
         $stat = ['origin' => 'Youtube', 'type' => 'search', 'data' => $channel, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
         $collection->insertOne($stat);
     }
     $params = ['q' => $keyword, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 30];
     $videos = Yt::searchAdvanced($params, true)['results'];
     if (!empty($videos)) {
         $collection = new \MongoDB\Collection($manager, 'laravel.videos');
         $collection->deleteMany([]);
         foreach ($videos as $video) {
             $collection = new \MongoDB\Collection($manager, 'laravel.videos');
             $stat = ['data' => $video, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     Log::info("Import de l'API Youtube video done! ");
 }
示例#3
0
 /**
  * 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.');
     }
 }
示例#4
0
 public function index()
 {
     $channel = Youtube::getChannelById('UCZBzhwB0w9M686PF7Z649Nw');
     if (!empty($channel->id)) {
         //dd($channel->statistics->viewCount);
         $data = array('id' => $channel->id, 'title' => $channel->snippet->title, 'description' => $channel->snippet->description, 'viewcount' => $channel->statistics->viewCount, 'subscribers' => $channel->statistics->subscriberCount, 'comments' => $channel->statistics->commentCount, 'videos' => $channel->statistics->videoCount);
         return view('dashboard')->with('data', $data);
     } else {
         return 'sorry, connecting to youtube failed';
     }
 }
 public function show($id)
 {
     try {
         $response = ['playlist' => []];
         $statusCode = 200;
         $playlist = Youtube::getPlaylistById($id, ['contentDetails']);
         $response['playlist'][] = ['id' => $playlist->id, 'contentDetails' => $playlist->contentDetails];
     } catch (\Exception $e) {
         Log::info($e);
         $statusCode = 404;
     } finally {
         return Response::json($response, $statusCode);
     }
 }
示例#6
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $keyword = $this->argument('keyword');
     $channel = Yt::getChannelByName('allocine');
     if (!empty($channel)) {
         DB::connection('mongodb')->collection('stats')->where(['origin' => 'Youtube', 'type' => 'infos'])->delete();
         $stat = new Stats();
         $stat->origin = "Youtube";
         $stat->type = "infos";
         $stat->data = $channel;
         $stat->save();
     }
     $params = array('q' => $keyword, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 30);
     $videos = Yt::searchAdvanced($params, true)['results'];
     if (!empty($videos)) {
         DB::connection('mongodb')->collection('videos')->delete();
         foreach ($videos as $video) {
             $vi = new Videos();
             $vi->data = $video;
             $vi->save();
         }
     }
     Log::info("Import de l'API Youtube video done! ");
 }
示例#7
0
 /**
  * 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');
 }
示例#8
0
 public function addMusic(Request $request)
 {
     $artist = $request->artist;
     $name = $request->name;
     $playlist_id = $request->playlist_id;
     $link = $request->link;
     $playlistVideo = false;
     $video_id = Youtube::parseVidFromUrl($link);
     // Si l'utilisateur est connecté, sinon on utilise l'utilisateur null null id=1
     $user_id = Auth::check() ? Auth::user()->id : 1;
     $vid = Video::where('url', $video_id)->first();
     $vid2 = Video::where('artist', 'LIKE', $artist)->where('name', 'LIKE', $name)->first();
     $check = !empty($vid) || !empty($vid2);
     if ($check) {
         if (!empty($vid)) {
             $pv = PlaylistVideo::where('video_id', $vid->id)->first();
         }
         if (empty($pv)) {
             if (!empty($vid)) {
                 $playlistVideo = PlaylistVideo::create(['video_id' => $vid->id, 'playlist_id' => $playlist_id, 'user_id' => $user_id]);
             } elseif (!empty($vid2)) {
                 $playlistVideo = PlaylistVideo::create(['video_id' => $vid2->id, 'playlist_id' => $playlist_id, 'user_id' => $user_id]);
             }
         }
     } else {
         $video = Video::create(['url' => $video_id, 'name' => $name, 'artist' => $artist, 'tags' => strtolower($name) . ' ' . strtolower($artist)]);
         $playlistVideo = PlaylistVideo::create(['video_id' => $video->id, 'playlist_id' => $playlist_id, 'user_id' => $user_id]);
     }
     if ($playlistVideo != false) {
         $playlistVideo->load('video');
     }
     return response()->json($playlistVideo);
 }
示例#9
0
 public static function getPopularVideo()
 {
     return Youtube::getPopularVideos('US');
 }