Using playlistitem.insert via one link

20 views Asked by At

I've been able to do video searches and read info using just one link that starts with googleapis.com but for the playlistitemsinsert to put videos into a playlist, I'm having trouble with the syntax. I'm trying to randomize the order of videos in a YouTube playlist. I understand you can shuffle play but its easier for me to remove the videos if they're played in chronological order, also its easier to go back to a video you recently watched.

I have all of the video ids in a column in excel I'm just not sure how to use vba to do a POST HTTP request to insert the videos into a playlist. Can you help me with the syntax on this?

1

There are 1 answers

0
jcb01 On

Although not using excel as database This works using youtube api. and users youtube created play list . shuffles the play list into new order every time page is refreshes

  1. Load YT-player API.
  2. Load YT-playlist user playlist id "**.youtube.com/playlist?list=PLo16_*******"
  3. To Shuffle playlist use > player.setShuffle(true);
  4. To Start YT-player at video 1 in shuffled playlist use > player.playVideoAt(0)

working demo Responsive shuffled YouTube Playlist on Google sites

code jsfiddle.net

<!DOCTYPE html>
<html>
<!-- Responsive YouTube shuffled playlist player -->
<head>
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag.  
style =  replaces  size in the player script makes it responsive -->

<div style=" top: 0; left: 0; width: 100%; height: 100%; position: absolute;" 
id='player'>
</div>
</body>

<script>
  // 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  // 3. This function creates an <iframe> (and YouTube player)
  //    after the API code downloads.
var player;

function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
playerVars: {
  autoplay: 0,
  loop: 1,
  controls: 1,
  showinfo: 1,
  frameborder: 1,
  'listType': 'playlist',
  'list': "PLo16_DLriHp4A8BvkJFZfO_4KDVv7yGgy", // your YouTube playlist id here
 },

 events: {
  'onReady': onPlayerReady,
  'onStateChange': onPlayerStateChange
 }
 });
 }

  // 4. The API will call this function when the video player is ready.

 function onPlayerReady(event) {
  // first shuffle play list 

 player.setShuffle(true); 

  // Onload and on refresh shuffles the users YT playlist but always starts playing 
  // the first video in the original list at its new index position 
  //ie. video (1) = video( new shuffled pos ?)
  // to get over this we can start the player at the new shuffled playlist 
  //video 1(index=0) this changes every time it's refreshed

 player.playVideoAt(0) 

 }
  // 5. The API calls this function when the player's state changes.
  //  option to to add bits         
 function onPlayerStateChange(event) {
  const player = event.target;
 }

 </script>

 </html>