/** * Test skipped for now, since the API returns Error 500 */ public function testNotFoundAPICall() { $vID = 'Utn7NBtbHL4'; //an deleted video $response = $this->youtube->getVideoInfo($vID); $this->assertFalse($response); }
/** * Create a Youtube media * * @param string $url * @return array */ public function create(string $url) : array { $config = $this->config; /* @service YoutubeDriver */ $service = new YoutubeDriver(['key' => $config['api_key']]); $videoId = $service->parseVIdFromURL($url); $video = $service->getVideoInfo($videoId); return (array) $video; }
/** * * @return type */ public function store(Request $request) { $this->validate($request, ['youtube_id' => 'required|unique:videos|max:20']); $videoId = Input::get('youtube_id'); // Process Video // Connect to youtube $youtubeKey = array("key" => "AIzaSyAmsWXPu2gP78el5mSftCeLLRCdvWfOHWU"); $youtube = new Youtube($youtubeKey); // Get video Info $videoInfo = $youtube->getVideoInfo($videoId); // dd($videoInfo->snippet); $user = Video::create(['youtube_id' => $videoId]); $data = ['video' => $videoInfo->snippet]; return Redirect::route('video.list', $data); }
protected function execute(InputInterface $input, OutputInterface $output) { // Direct access to the Container. /** @var Kengrabber $kg */ $kg = $this->getApplication()->getContainer(); $output->writeln("Starting with fetching the videos from channel: " . $kg['config']['youtube_channel_username']); $yt = new Youtube(array('key' => $kg['config']['youtube_api_key'])); $channel = $yt->getChannelByName($kg['config']['youtube_channel_username']); // Setting channel data... $kg['option']->setOption('channel.title', $channel->snippet->title); $kg['option']->setOption('channel.description', $channel->snippet->description); $params = array('type' => 'video', 'channelId' => $channel->id, 'maxResults' => 15, 'order' => 'date', 'safeSearch' => 'none', 'part' => 'id, snippet'); foreach ($kg['config']['youtube_queries'] as $query) { $params['q'] = $query; do { $search = $yt->searchAdvanced($params, true); if (is_array($search['results'])) { foreach ($search['results'] as $v) { $vid = $yt->getVideoInfo($v->id->videoId); /** @var Video $video */ $video = $kg['video']->getVideoById($vid->id); if ($video === null) { $video = new Video(); $video->setId($vid->id); } $video->setTitle($vid->snippet->title); $video->setDescription($vid->snippet->description); $video->setPublished(new \DateTime($vid->snippet->publishedAt)); $kg['video']->saveVideo($video); } } if (isset($search['info']['nextPageToken'])) { $params['pageToken'] = $search['info']['nextPageToken']; $output->writeln("Go to next page..."); } else { break; } } while (true); } $output->writeln("Finished crawling..."); }