Youtube 允许您在自己的频道上programmatically create playlists 和add items to playlists。
playlistItems/insert 调用还允许您为剪辑提供 specify 和 position、startAt 和 endAt 属性,这似乎涵盖了您的用例。
使用此 API 的一个注意事项 - 您必须是 registered with them to use it
播放列表可以包含up to 200 videos
UPD
我运行了以下 API 请求并成功创建了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
但是,YouTube 似乎有 deprecated、contentDetails.startAt 和 contentDetails.endAt,我建议你依赖它们:开始时间似乎仍然有效,但剪辑一直播放到结束。
我建议您查看来自 this SO thread 的建议 - 您也许可以从那里的答案中汲取一些想法(例如在播放器中使用 3rd 方或 Javascript 事件)