Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addVideosToPlaylist() {
- var ss = SpreadsheetApp.getActiveSpreadsheet();
- var videoIdSheet = ss.getSheetByName('Sheet1'); // Change to the name of your sheet if different
- // Get the values in column A (A2:A) as video IDs. This assumes you have a column header in A1 on Sheet1 per your original code
- var videoIds = videoIdSheet.getRange("A2:A" + videoIdSheet.getLastRow()).getValues();
- // Get the YouTube playlist ID by name.
- var destinationPlaylistId = 'PutYourIdHere'
- // Add each video to the playlist.
- for (var i = 0; i < videoIds.length; i++) {
- if (videoIds[i][0]) { // Check if the cell is not empty
- addVideoToPlaylist(videoIds[i][0], destinationPlaylistId);
- }
- }
- Logger.log("Videos added to the playlist successfully.");
- }
- function addVideoToPlaylist(videoId, destinationPlaylistId) {
- YouTube.PlaylistItems.insert({
- snippet: {
- playlistId: destinationPlaylistId,
- resourceId: {
- kind: "youtube#video",
- videoId: videoId
- }
- }
- },"snippet");
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement