Skip to content

Conversation

grant
Copy link
Contributor

@grant grant commented Oct 29, 2018

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.

@grant
Copy link
Contributor Author

grant commented Oct 29, 2018

Besides the 2 Travis lint failures, PTAL.

});

var json = [];
for (var i = 0; i < youTubeResults.items.length; i++) {

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
};
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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.

function createSlides() {
var youTubeVideos = getYouTubeVideosJSON(YOUTUBE_QUERY);
var presentation = SlidesApp.create(PRESENTATION_TITLE);
presentation.getSlides()[0].getPageElements()[0].asShape().getText().setText(PRESENTATION_TITLE);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// 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) {

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.

Copy link
Contributor Author

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 👍

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) {

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.

Copy link
Contributor Author

@grant grant left a 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

});

var json = [];
for (var i = 0; i < youTubeResults.items.length; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

function createSlides() {
var youTubeVideos = getYouTubeVideosJSON(YOUTUBE_QUERY);
var presentation = SlidesApp.create(PRESENTATION_TITLE);
presentation.getSlides()[0].getPageElements()[0].asShape().getText().setText(PRESENTATION_TITLE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// 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) {
Copy link
Contributor Author

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 👍

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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

});

var json = [];
for (var i = 0; i < youTubeResults.items.length; i++) {

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.

@grant
Copy link
Contributor Author

grant commented Oct 30, 2018

You still appear to be using a for loop here.

I removed for-i loops.
I took optional comments as optional. I ended up using the forEach loop.

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 function prototype. As such, forEach is not used in modern JS and I prefer not using them.

The diff will be a bit bigger if we convert every for loop to forEach rather than for-i/for-of.

@grant
Copy link
Contributor Author

grant commented Oct 31, 2018

@erickoledadevrel PTAL.

Copy link

@erickoledadevrel erickoledadevrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grant grant merged commit 3eb38f7 into master Nov 1, 2018
@grant grant deleted the grant-youtube branch November 1, 2018 18:00
brentchang pushed a commit to brentchang/apps-script-samples that referenced this pull request Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants