Created
July 24, 2018 16:21
-
-
Save grant/deac361090e4f0019684f2669c89e9e0 to your computer and use it in GitHub Desktop.
Create a Saxophone tutorial presentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PRESENTATION_TITLE = 'Saxophone Tutorials'; | |
var YOUTUBE_QUERY = 'saxophone tutorials'; | |
/** | |
* Gets a list of YouTube videos. | |
* @param {String} query - The query term to search for. | |
* @ref https://developers.google.com/youtube/v3/docs/search/list | |
*/ | |
function getYouTubeVideosJSON(query) { | |
var youTubeResults = YouTube.Search.list('id,snippet', { | |
q: query, | |
maxResults: 10 | |
}); | |
var json = []; | |
for (var i = 0; i < youTubeResults.items.length; i++) { | |
var item = youTubeResults.items[i]; | |
json[i] = { | |
url: 'https://youtu.be/' + item.id.videoId, | |
title: item.snippet.title, | |
thumbnailUrl: item.snippet.thumbnails.high.url | |
}; | |
} | |
return json; | |
} | |
/** | |
* Creates a presentation where each slide features a YouTube video. | |
* Logs out the URL of the presentation. | |
*/ | |
function createSlides() { | |
var youTubeVideos = getYouTubeVideosJSON(YOUTUBE_QUERY); | |
var presentation = SlidesApp.create(PRESENTATION_TITLE); | |
// Insert saxophone image | |
presentation.getSlides()[0].insertImage("https://i.imgur.com/G7CQA4f.gif", 270, 200, 200, 300); | |
presentation.getSlides()[0].getPageElements()[0].asShape().getText().setText(PRESENTATION_TITLE); | |
// Add slides with videos and log the presentation URL to the user. | |
for (var i = 0; i < youTubeVideos.length; ++i) { | |
var slide = presentation.appendSlide(); | |
slide.insertVideo(youTubeVideos[i].url, 0, 0, presentation.getPageWidth(), presentation.getPageHeight()); | |
} | |
Logger.log(presentation.getUrl()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment