-
Notifications
You must be signed in to change notification settings - Fork 2k
Add YouTube + Slides Demo #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Besides the 2 Travis lint failures, PTAL. |
advanced/youtube.gs
Outdated
}); | ||
|
||
var json = []; | ||
for (var i = 0; i < youTubeResults.items.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Use map() here instead.
return youTubeResults.items.map(function(item) {
return {
url: 'https://youtu.be/' + item.id.videoId,
title: item.snippet.title,
thumbnailUrl: item.snippet.thumbnails.high.url
};
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still appear to be using a for loop here.
advanced/youtube.gs
Outdated
function createSlides() { | ||
var youTubeVideos = getYouTubeVideosJSON(YOUTUBE_QUERY); | ||
var presentation = SlidesApp.create(PRESENTATION_TITLE); | ||
presentation.getSlides()[0].getPageElements()[0].asShape().getText().setText(PRESENTATION_TITLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
advanced/youtube.gs
Outdated
for (var i = 0; i < youTubeVideos.length; ++i) { | ||
if (youTubeVideos[i].url.indexOf('undefined') === -1) { | ||
var slide = presentation.appendSlide(); | ||
slide.insertVideo(youTubeVideos[i].url, 0, 0, presentation.getPageWidth(), presentation.getPageHeight()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
advanced/youtube.gs
Outdated
|
||
// Add slides with videos and log the presentation URL to the user. | ||
for (var i = 0; i < youTubeVideos.length; ++i) { | ||
if (youTubeVideos[i].url.indexOf('undefined') === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this case occur? Suggesting filtering it out upstream when you get the JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe some videos are private but still show up in the API with limited data.
I've moved this filter upstream as suggested 👍
advanced/youtube.gs
Outdated
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Use youTubeVideos.forEach() instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated sample with comments.
Tested on script.google.com
PTAL
advanced/youtube.gs
Outdated
}); | ||
|
||
var json = []; | ||
for (var i = 0; i < youTubeResults.items.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
advanced/youtube.gs
Outdated
function createSlides() { | ||
var youTubeVideos = getYouTubeVideosJSON(YOUTUBE_QUERY); | ||
var presentation = SlidesApp.create(PRESENTATION_TITLE); | ||
presentation.getSlides()[0].getPageElements()[0].asShape().getText().setText(PRESENTATION_TITLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
advanced/youtube.gs
Outdated
|
||
// Add slides with videos and log the presentation URL to the user. | ||
for (var i = 0; i < youTubeVideos.length; ++i) { | ||
if (youTubeVideos[i].url.indexOf('undefined') === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe some videos are private but still show up in the API with limited data.
I've moved this filter upstream as suggested 👍
advanced/youtube.gs
Outdated
for (var i = 0; i < youTubeVideos.length; ++i) { | ||
if (youTubeVideos[i].url.indexOf('undefined') === -1) { | ||
var slide = presentation.appendSlide(); | ||
slide.insertVideo(youTubeVideos[i].url, 0, 0, presentation.getPageWidth(), presentation.getPageHeight()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
advanced/youtube.gs
Outdated
}); | ||
|
||
var json = []; | ||
for (var i = 0; i < youTubeResults.items.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still appear to be using a for loop here.
I removed for-i loops. We're going to eventually use V8 for-of loops, which uses native JS loops –rather than creating a new function closure with the forEach The diff will be a bit bigger if we convert every for loop to |
@erickoledadevrel PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add YouTube + Slides Demo
I use this demo in my "All About Apps Script Talks". I'd like to add it to GitHub so the sample doesn't get lost in my Drive files.
I can additionally create a quickstart/article with this demo if needbe.