Advertisement
Guest User

Untitled

a guest
Oct 11th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function addVideosToPlaylist() {
  2. var ss = SpreadsheetApp.getActiveSpreadsheet();
  3. var videoIdSheet = ss.getSheetByName('Sheet1'); // Change to the name of your sheet if different
  4.  
  5. // 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
  6. var videoIds = videoIdSheet.getRange("A2:A" + videoIdSheet.getLastRow()).getValues();
  7.  
  8. // Get the YouTube playlist ID by name.
  9. var destinationPlaylistId = 'PutYourIdHere'
  10.  
  11. // Add each video to the playlist.
  12. for (var i = 0; i < videoIds.length; i++) {
  13. if (videoIds[i][0]) { // Check if the cell is not empty
  14. addVideoToPlaylist(videoIds[i][0], destinationPlaylistId);
  15. }
  16. }
  17. Logger.log("Videos added to the playlist successfully.");
  18. }
  19.  
  20.  
  21. function addVideoToPlaylist(videoId, destinationPlaylistId) {
  22. YouTube.PlaylistItems.insert({
  23. snippet: {
  24. playlistId: destinationPlaylistId,
  25. resourceId: {
  26. kind: "youtube#video",
  27. videoId: videoId
  28. }
  29. }
  30. },"snippet");
  31. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement