Reputation: 170
Ok, so based on this video; https://www.youtube.com/watch?v=7tjfeEAdY0I
I'm curious if it's possible to create a PHP script that will automatically grab all video's on a certain youtube channel (in this example; https://www.youtube.com/user/whitehouse/videos), grab all videos, check out the transcripts for a certain line or word, then save the vids with the correct timestamp, to make it possible to merge all these video's into one.
I know there's an API available to get all youtube video url's of a specific user, and you can get the transcripts per video, but scanning through all of them will be quite resource-heavy. I'm curious if you guys have any ideas on how to create such a script.
Upvotes: 3
Views: 516
Reputation: 899
It is possible to capture all information related to videos of a particular YouTube channel using the YouTube V3 API.
The documentation of YouTube API can be found here
The related API functionality can be found here
The procedure to retrieve the transcript of a video from the json response from the API call will not be resource intensive and can be achieved in line of code as json parsing is a standard procedure and is supported on most of the languages including PHP.
Using the PHP wrapper, this can be achieved in a few lines of code.
Procedure:
Firstly, a request to listChannels under channels is send to receive all content details regarding a particular YouTube channel denoted by a channel ID. The related code snippet is:
$channelsResponse = $service->channels->listChannels('contentDetails', array('forUsername' => $channelId));
The second step is to parse through each video item which is done conveniently using a for loop like:
foreach ($channelsResponse['items'] as $channel) {}
The third step is to get the upload list id from the current item and send another request to the API with the parameter 'snippet'.
At this point, you will have all the content related data in json format and you need to parse and get the desired information.
The entire code snippet is :
$channelsResponse = $service->channels->listChannels('contentDetails', array('forUsername' => $channelId));
$data = [];
foreach ($channelsResponse['items'] as $channel)
{
$uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];
$playlistItemsResponse = $service->playlistItems->listPlaylistItems(
'snippet', array(
'playlistId' => $uploadsListId,
'maxResults' => 50
)
);
foreach ($playlistItemsResponse['items'] as $playlistItem)
{
$data[] = $playlistItem['snippet'];
}
}
Upvotes: 4