Ayan Mullick
Ayan Mullick

Reputation: 162

Multiple YouTube videos in a single embed URL

Is it possible to create a single embed URL with multiple videos' start and end times; like below?

http://www.youtube.com/embed/VTNSdABrKAI?start=134&end=225/embed/I4LoGhyb2uc?start=172&end=257

So the next clip plays in the same video frame instead of putting multiple embed URLs on a webpage;

http://www.youtube.com/embed/VTNSdABrKAI?start=134&end=225

http://www.youtube.com/embed/I4LoGhyb2uc?start=172&end=257

Or avoid creating, editing and uploading a whole new YouTube video and dealing with copyright claims like below?

https://www.youtube.com/watch?v=9DNmc618JwE

Upvotes: 2

Views: 2571

Answers (1)

timur
timur

Reputation: 14567

Youtube allows you to programmatically create playlists on your channel and add items to playlists. The playlistItems/insert call also lets you specify a position, startAt and endAt properties for a clip, which seems to cover your use case.

One caveat to using this API - you have to be registered with them to use it

A playlist can contain up to 200 videos

UPD I ran the following API requests and was able to successfully create a playlist.

curl --request POST \
  'https://www.googleapis.com/youtube/v3/playlists?part=snippet%2Cstatus&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"snippet":{"title":"Sample playlist created via API","description":"This is a sample playlist description."},"status":{"privacyStatus":"unlisted"}}' \
  --compressed
curl --request POST \
  'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"snippet":{"playlistId":"PL5W0uIHD5lLZAK1reCuTDFpGMPygNDWvm","position":0,"resourceId":{"kind":"youtube#video","videoId":"PLOPygVcaVE"}},"contentDetails":{"videoId":"PLOPygVcaVE","startAt":"PT4H37M0.000S","endAt":"PT4H38M0.000S"}}' \
  --compressed
curl --request POST \
  'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"snippet":{"playlistId":"PL5W0uIHD5lLZAK1reCuTDFpGMPygNDWvm","position":1,"resourceId":{"kind":"youtube#video","videoId":"L_LUpnjgPso"}},"contentDetails":{"videoId":"L_LUpnjgPso","startAt":"PT8H37M0.000S","endAt":"PT8H38M0.000S"}}' \
  --compressed

But, it appears, Youtube have deprecated the contentDetails.startAt and contentDetails.endAt that I was suggesting you to rely on: start time seems to still work, but the clip plays through to the end.

I would suggest checking out suggestions from this SO thread - you might be able to leverage some idea from answers there (like using 3rd parties or Javascript events in the player)

Upvotes: 2

Related Questions