39 Comments

thanks mate. been looking to do something like this for quite some time. you saved me the hassle of doing it myself. I tweaked it just a tad though. I added a PlayList ID in Column E so I can add videos to separate playlists and I reversed the order of which it checks videos:

for(var j=maxVideosToCheck-1;j>=0;j--)

So it adds them in chronological order (important for some channels). This makes the third page add videos much faster than intended and also makes lastVideoID much less useful. But it's manageable for now.

I really appreciate it.

Expand full comment

In my own script, I have that multiple Playlist ID option, but here I wanted to put something non-programmers would find easy to use.

As you are checking videos in reverse order, make sure to replace the "break" statement with "continue" statement in the "if" clause inside the "for loop". Otherwise, it will just break the code off, even if there are new videos.

Expand full comment

Thank you, Tech angel!

Expand full comment

:)

Expand full comment

hello mate! is it possible to also like, or dislike, the videos that are being added?

Expand full comment

A bit late to the party - this is excellent!

Is there a way to have the script auto edit both the ID's from an additional sheet so you could have a multiple playlists updating from the one document. Great Work and thanks for sharing... Toolmaker / coding noob / x-UI/UX Designer. Manolo

Expand full comment
Mar 9Edited

Just checking in if this still works as of March 9th 2024? I have it all setup and it seems to be partially working, that is it added a few videos to the playlist I setup from the channels I added to the google sheet, but only videos from 3 channels of the 18? Its running with no errors output to me. Also is there anyway to stop it from adding youtube shorts?

Expand full comment

Hi! Thanks for making this. I’ve been getting the following error when running the script:

TypeError: Cannot read properties of undefined (reading ‘id’) at myFunction(Code:59:67)

I’ve edited spreadsheetID, playlistID, and maxVideosToCheck (set to 300, which is high, but I wanted to add a large backlog to my playlist). Would really appreciate if you could point me toward what might be causing the error.

Expand full comment

This is awesome, thank you! Is there a way to find out what are daily quota is. Right now if I exceed it I just get an email telling me that, but no way of knowing how much I need to cut back. Thanks!

Expand full comment

Depends on which quota you are exceeding. You can find the quotas on this link: https://developers.google.com/apps-script/guides/services/quotas

Expand full comment

Hello, just wonder is this app still working in 2023, because when i input the channel id name, the name and last video id didn't update automatically... :(

Expand full comment

It still works. Did you try running the script? What error did it show?

Expand full comment

Thanks for your reply! I tried to run the script and it worked! I thought those fields are able to update instantly without running the script ;) Btw, I have another question, is that possible that i could change the code to target a specific playlist instead of a channel? Is that easy to do? Thanks!!🙏

Expand full comment

Can you please elaborate? Do you mean when a video is added to the "specific playlist", it gets added to your playlist?

Expand full comment

Hi, is there anyway to automatically or manually remove watched videos in bulk?

Expand full comment

You might have to do some trial and error for it. Some code like this could work:

var playlist = youtube.playlistItems.list('id, contentDetails', {playlistId: channelId, maxResults: 50});

var watchHistory = [];

for (var i = 0; i < playlist.items.length; i++) {

var videoId = playlist.items[i].contentDetails.videoId;

var video = youtube.videos.list('snippet, contentDetails', {id: videoId});

watchHistory.push(video.items[0]);

}

return watchHistory;

Expand full comment

7:24:52 PM Error

GoogleJsonResponseException: API call to youtube.search.list failed with error: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.

myFunction @ Code.gs:51

Expand full comment

There is a set amount of requests google allows per user. You can find the quotas on this link: https://developers.google.com/apps-script/guides/services/quotas

Expand full comment

Any chance you could update this to include a filter for keywords? I do want to watch videos with a certain title that regularly get uploaded, like "a closer look" with seth myers, but I don't care about the celebrety interviews and stuff. An extra column in the google sheet where you could enter keywords so only videos matching them get added would be awesome. I tried looking into how to do this myself, but I suck a programming :)

Expand full comment

I haven't tried this yet, but you can use something like "item.snippet.title" just before adding the video to the playlist. Check if the title of the item (i.e. video) has strings like "a closer look", if it does, then proceed to add it to the playlist.

hope this works

Expand full comment

I'm confused on how many videos can be added at a time based off the quotas, I listen to a lot of new music, I usually manually add 500ish videos and subscribe to about 500 channels, if I run it manually once a day. Will the quotas be a problem to even be worth to set up the script?

Expand full comment

500 channels is a lot. I have like 20 channels in my sheet, but every few weeks, I get a notification, that I surpassed my daily limit.

Expand full comment

Hey, I hope you're still watching the comment section here because i got an error. I’m not a programmer, so I don't know what it means and how i can fix it. It is the following

GoogleJsonResponseException: API call to youtube.search.list failed with error: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.

The error seems to occur at Line 51 according to Google App Script

Expand full comment

There is a quota set to our accounts. That means only some amount of data you can query from YouTube each day. You can find exact amout of quota here: https://developers.google.com/youtube/v3/determine_quota_cost.

Don't worry try after a day or so and you will stop receiving this error.

Expand full comment

Thanks for your help but I got the error the first time I ran it. For clarification: I currently have 60 channels and I make the code (if I understand line 9 correctly) watch the last 3 videos at a time. So that's 180 requests if I'm not mistaken? Furthermore, I want to run it every hour, which would be 4320 requests. However, I don't see a value high enough to do that in the link you gave me. Am I misunderstanding something or is the problem the amount of requests? If the latter, is there a way to increase it?

Expand full comment

Yes you are understanding everything properly.

60 channels is too much and on top of that every hour is overkill. With my 20 or so channels, I run it every 12 hours. You can do one of these 2 things:

1) Reduce the number of channels.

2) Run it manually everytime you want to watch YouTube.

Expand full comment

This seems not to work when using a Brand Account with YouTube. The videos don't get added to the new playlist: "GoogleJsonResponseException: API call to youtube.playlistItems.insert failed with error: Forbidden"

Expand full comment

Were you trying to add videos to "watch later" playlist? Google Apps Script doesn't allow you to add videos to your "watch later" playlist through scripts. You need to make a new playlist.

The other reason might be that, the playlist has the maximum amount of videos possible (i.e. 5,000).

Expand full comment

I had the same issue and solved it:

I did not know, that a Youtube-channel works kind of like a second Youtube-account. Thus, since I created a Youtube-channel a few years ago, I have been using the channel's account by default. And thus, the playlist I created for this script, was created for the channel's account.

But my normal Google-account seems to lack permission for this playlist. At least via the API.

Solution for me:

Change the default Youtube-account back to my Google-account (top right in the browser) and created a new playlist there.

Expand full comment

You can export and add all your subscriptions at once with these steps:

1. Make sure you are logged in with the Google account you use for Youtube

2. Go to https://takeout.google.com/takeout/custom/youtube

3. Click on the button "All YouTube data included"

4. Selec only subscriptions and click "OK"

5. Click "Next step"

6. Click "Create export"

7. Once the download is ready, click it

8. In the ZIP file you'll find a JSON file, open it with excel or similar

9. Copy the first column to your google sheet

Expand full comment

Nice idea!

Expand full comment

hey... thanks for the post.. it worked fine when I used the copy of your google sheet.. however it is not adding videos to my playlist when i try to edit or add channel ID... is there a special way to do that?? I simply "paste as text only" the channel id below the 4 channels you provided

P.s. - it recognizes the new channel name and last video id correctly.. it just doesn't add to watched videos sheet and neither to my actual playlist...

Expand full comment

Did you wait for the creators to upload new videos after you added them to your list in Google Sheets? Only after they upload new videos, the videos will be added to your playlist.

Did you remember to set the Triggers (bit.ly/3kxX5jc) in Google Apps Script?

Try adding the video id of the last second video of a particular channel and then run the script. If the last video is added to your playlist then you are doing everything correctly, you just need to wait for the creators to upload videos.

Did you run it first through the Apps Script tab directly once to give all the permissions? (bit.ly/3hKfzem) Without the permissions, the code won't run in the background.

Google Apps Script doesn't allow you to add videos to your watch later playlist through scripts. You need to make a new playlist. Were you trying to add videos in "WL"?

Expand full comment