Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP :- Scraping Data From Youtube Video URL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.78k
    Comment on it

    You can also get the data i.e title, description, thumbnail_url, etc from the Youtube video url by using following script. Remember you need to put the YOUR_GOOGLE_DEVELOPMENT_KEY which you can generate by creating account in Google Developer Console.

    PHP Script :-

    $url = $data['url'];
    if(strpos($url, 'https://youtube.com/embed/') === false){//OLD
        parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
        $videoid = $my_array_of_vars['v'];
    } else {//NEW
        $urlArray = explode('https://youtube.com/embed/', $url);
        $videoid = $urlArray[1]; 
    }
    $embedurl = "https://youtube.com/embed/".$videoid;
    $json = json_decode( file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=".$videoid."&key=YOUR_GOOGLE_DEVELOPMENT_KEY&part=snippet,contentDetails,statistics,status") );
    $data['title'] = $json->items[0]->snippet->title;
    $data['description'] = $json->items[0]->snippet->description;
    $data['thumbnail_url'] = $json->items[0]->snippet->thumbnails->medium->url;
    $data['url'] = $embedurl;
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: