Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get all videos ID's from a Youtube channel

How can I get all video id's from the youtube data feed?

I receive the youtube feed via this (API) URL: http://gdata.youtube.com/feeds/base/users/#userid#/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile

I already know how to extract the links, descriptions and thumbnails from a Channel, but I want to extract all the video Id's from a Channel (e.g. http://www.youtube.com/watch?v=WWooNnPnHTs)

like image 395
Jake Avatar asked Jun 13 '11 13:06

Jake


2 Answers

This is my way. Slow, but it works. :)

function getVideos($channel){
    if($channel == ""){
        return false;   
    }
    /* Get number of videos */
    $books = simplexml_load_file('http://gdata.youtube.com/feeds/base/users/'.$channel.'/uploads?max-results=1&start-index=1');
    $numb_videos = $books->children( 'openSearch', true )->totalResults; 
    settype($numb_videos, "integer");

    $ids = array();
    $i = 1;
    for($i = 1; $i <= $numb_videos; $i++){
        $books = simplexml_load_file('http://gdata.youtube.com/feeds/base/users/'.$channel.'/uploads?max-results=1&start-index='.$i);
        $ApiLink  = $books->entry->id;
        settype($ApiLink, "string");
        $ApiLink = str_replace("http://gdata.youtube.com/feeds/base/videos/", "", $ApiLink);
        array_push($ids, $ApiLink);
    }
    return $ids;    
}
like image 130
Fred Avatar answered Sep 20 '22 05:09

Fred


Use this:

GET https://www.googleapis.com/youtube/v3/search?part=id&channelId=UC9MAhZQQd9egwWCxrwSIsJQ&maxResults=10&order=date&key={YOUR_API_KEY}

And you will get a result for the above url as:

200 OK

- Show headers -

{
"kind": "youtube#searchListResponse",
"etag": "\"qQvmwbutd8GSt4eS4lhnzoWBZs0/WiiEAt3fgPkFw_831Iveo6mV-IU\"",
"nextPageToken": "CAQQAA",
"pageInfo": {
"totalResults": 1046,
"resultsPerPage": 4
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"qQvmwbutd8GSt4eS4lhnzoWBZs0/OtU1Ja-W-gNf83iiXWzodKk3Ce0\"",
"id": {
"kind": "youtube#video",
"videoId": "jKLMD-LXIgk"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"qQvmwbutd8GSt4eS4lhnzoWBZs0/EUhMCxemh2UGmf2ufGS0IYdcMUs\"",
"id": {
"kind": "youtube#video",
"videoId": "glCQQeH_ddw"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"qQvmwbutd8GSt4eS4lhnzoWBZs0/2IMOnedhjKXxnFZy-PNg5o80kkY\"",
"id": {
"kind": "youtube#video",
"videoId": "yB78MIcmDxs"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"qQvmwbutd8GSt4eS4lhnzoWBZs0/oEb7q9_GwGdXcHsvuRDuNmh_rGQ\"",
"id": {
"kind": "youtube#video",
"videoId": "NnkDja1cXlo"
}
}
]
}

For more reference you may check here

like image 20
akshay Avatar answered Sep 20 '22 05:09

akshay