embed.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. var video_data = JSON.parse(document.getElementById('video_data').textContent);
  3. function get_playlist(plid) {
  4. var plid_url;
  5. if (plid.startsWith('RD')) {
  6. plid_url = '/api/v1/mixes/' + plid +
  7. '?continuation=' + video_data.id +
  8. '&format=html&hl=' + video_data.preferences.locale;
  9. } else {
  10. plid_url = '/api/v1/playlists/' + plid +
  11. '?index=' + video_data.index +
  12. '&continuation' + video_data.id +
  13. '&format=html&hl=' + video_data.preferences.locale;
  14. }
  15. helpers.xhr('GET', plid_url, {retries: 5, entity_name: 'playlist'}, {
  16. on200: function (response) {
  17. if (!response.nextVideo)
  18. return;
  19. player.on('ended', function () {
  20. var url = new URL('https://example.com/embed/' + response.nextVideo);
  21. url.searchParams.set('list', plid);
  22. if (!plid.startsWith('RD'))
  23. url.searchParams.set('index', response.index);
  24. if (video_data.params.autoplay || video_data.params.continue_autoplay)
  25. url.searchParams.set('autoplay', '1');
  26. if (video_data.params.listen !== video_data.preferences.listen)
  27. url.searchParams.set('listen', video_data.params.listen);
  28. if (video_data.params.speed !== video_data.preferences.speed)
  29. url.searchParams.set('speed', video_data.params.speed);
  30. if (video_data.params.local !== video_data.preferences.local)
  31. url.searchParams.set('local', video_data.params.local);
  32. location.assign(url.pathname + url.search);
  33. });
  34. }
  35. });
  36. }
  37. addEventListener('load', function (e) {
  38. if (video_data.plid) {
  39. get_playlist(video_data.plid);
  40. } else if (video_data.video_series) {
  41. player.on('ended', function () {
  42. var url = new URL('https://example.com/embed/' + video_data.video_series.shift());
  43. if (video_data.params.autoplay || video_data.params.continue_autoplay)
  44. url.searchParams.set('autoplay', '1');
  45. if (video_data.params.listen !== video_data.preferences.listen)
  46. url.searchParams.set('listen', video_data.params.listen);
  47. if (video_data.params.speed !== video_data.preferences.speed)
  48. url.searchParams.set('speed', video_data.params.speed);
  49. if (video_data.params.local !== video_data.preferences.local)
  50. url.searchParams.set('local', video_data.params.local);
  51. if (video_data.video_series.length !== 0)
  52. url.searchParams.set('playlist', video_data.video_series.join(','));
  53. location.assign(url.pathname + url.search);
  54. });
  55. }
  56. });