示例#1
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! ");
 }
示例#2
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! ");
 }