plot thumbnail from trending youtube video in matlab

To plot a thumbnail from a trending YouTube video in MATLAB, you can use the YouTube API to retrieve the URL for the thumbnail image and then use the built-in MATLAB functions to load and display the image.

Here's some sample code to get you started:

main.m
% set up YouTube API credentials
api_key = 'your_api_key_here';

% make API request to get a list of current trending videos
url = ['https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular' ...
       '&regionCode=US&maxResults=5&key=' api_key];
result = urlread(url);
data = jsondecode(result);

% grab the first video's thumbnail URL
thumbnail_url = data.items(1).snippet.thumbnails.medium.url;

% load the image using MATLAB's imread function
img = imread(thumbnail_url);

% display the image using MATLAB's image function
imshow(img);
559 chars
18 lines

Note that in order to use the YouTube API, you'll need to sign up for an API key and include it in your requests. Also, this code only retrieves the first video from the list of trending videos - you can modify the API request to adjust the number of results returned or to filter by specific criteria.

gistlibby LogSnag