Skip to content

Instantly share code, notes, and snippets.

@Araxeus
Last active November 2, 2024 12:25
Show Gist options
  • Save Araxeus/fc574d0f31ba71d62215c0873a7b048e to your computer and use it in GitHub Desktop.
Save Araxeus/fc574d0f31ba71d62215c0873a7b048e to your computer and use it in GitHub Desktop.

see https://developers.google.com/youtube/iframe_api_reference

Navigating Youtube-Music without reload:

const id = getChannelID() || getOriginalAlbumID
$('ytmusic-app').navigate_(id)

note: albumID needs to be in original format, like in this link https://music.youtube.com/browse/MPREb_QzG0rdjYht1

and not like the address that it redirects to (https://music.youtube.com/playlist?list=OLAK5uy_kbMeriANLfv4JxNm5KlbyPwq1GmgCjmkY)

also you can "navigate" songs in the video player with api.loadVideoById() / api.loadVideoByUrl() (both in youtube and youtube-music)

Events:

$('#movie_player').addEventListener('videodatachange', (name, data) => console.log(name, data))
$('#movie_player').addEventListener('onStateChange', console.log);
$('#movie_player').addEventListener('onAdEnd', console.log);
$('#movie_player').addEventListener('onPlaybackStartExternal', console.log);

GENERAL YOUTUBE COMMANDS:

const moviePlayer = $("#movie_player")

moviePlayer.getPlayerState() = {
 1: playing
 2: paused
 5: not loaded yet !important // could be used to determine first song hasn't started
}
moviePlayer.playVideo
moviePlayer.pauseVideo

function playPause() {
	switch (moviePlayer.getPlayerState()) {
		case 1: moviePlayer.pauseVideo(); return;
		case 2: moviePlayer.playVideo(); return;
	}
}

METADATA:

moviePlayer.getVideoData() //MUSIC DATA
moviePlayer.getPlayerResponse() //FULL

moviePlayer.classList.contains("paused-mode") = video paused //("playing-mode") = video playing

moviePlayer.getProgressState() // .current, .duration and more
moviePlayer.getCurrentTime(), moviePlayer.getDuration()

moviePlayer.getPlaylistId()

QUALITY:

$("#movie_player").getAvailableQualityLabels()
$("#movie_player").getAvailableQualityLevels()
// length -2 should be smallest

PLAYBACK RATE:

$("#movie_player").getAvailablePlaybackRates()
(8) [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]

VOLUME:

moviePlayer.isMuted() = moviePlayer.hasOwnProperty('unMute')

if (newVolume > 0 && moviePlayer.isMuted()) {
 	moviePlayer.unMute();
} else if (newVolume === 0 && moviePlayer.hasOwnProperty('mute')) {
 	moviePlayer.mute();
}

LIST OF COMMANDS:

moviePlayer.getApiInterface()
moviePlayer.getInternalApiInterface()

EXTERNAL API: (moviePlayer.getApiInterface)

  1. cueVideoById()

  2. loadVideoById()

  3. cueVideoByUrl()

  4. loadVideoByUrl()

  5. playVideo()

  6. pauseVideo()

  7. stopVideo()

  8. clearVideo()

  9. getVideoBytesLoaded()

  10. getVideoBytesTotal()

  11. getVideoLoadedFraction()

  12. getVideoStartBytes()

  13. cuePlaylist()

  14. loadPlaylist()

  15. nextVideo()

  16. previousVideo()

  17. playVideoAt()

  18. setShuffle()

  19. setLoop()

  20. getPlaylist()

  21. getPlaylistIndex()

  22. getPlaylistId()

  23. loadModule()

  24. unloadModule()

  25. setOption()

  26. getOption()

  27. getOptions()

  28. mute()

  29. unMute()

  30. isMuted()

  31. setVolume()

  32. getVolume()

  33. seekTo()

  34. getPlayerState()

  35. getPlaybackRate()

  36. setPlaybackRate()

  37. getAvailablePlaybackRates()

  38. getPlaybackQuality()

  39. setPlaybackQuality()

  40. getAvailableQualityLevels()

  41. getCurrentTime()

  42. getDuration()

  43. addEventListener()

  44. removeEventListener()

  45. getDebugText()

  46. getVideoData()

  47. addCueRange()

  48. removeCueRange()

  49. setSize()

  50. getApiInterface()

  51. destroy()

  52. showVideoInfo()

  53. hideVideoInfo()

  54. isVideoInfoVisible()

  55. getSphericalProperties()

  56. setSphericalProperties()

  57. getVideoEmbedCode()

  58. getVideoUrl()

  59. getMediaReferenceTime()

  60. cueVideoByPlayerVars()

  61. loadVideoByPlayerVars()

  62. preloadVideoByPlayerVars()

  63. seekBy()

  64. mutedAutoplay()

  65. showControls()

  66. hideControls()

  67. cancelPlayback()

  68. getProgressState()

  69. isInline()

  70. setInline()

  71. getStoryboardFormat()

  72. getVideoContentRect()

  73. toggleFullscreen()

  74. isFullscreen()

  75. getVideoStats()

  76. getPlayerSize()

  77. toggleSubtitles()

  78. setCenterCrop()

  79. handleGlobalKeyDown()

  80. handleGlobalKeyUp()

  81. setSizeStyle()

  82. wakeUpControls()

EXTERNAL API. (moviePlayer.getInternalApiInterface())

  1. cueVideoById()

  2. loadVideoById()

  3. cueVideoByUrl()

  4. loadVideoByUrl()

  5. playVideo()

  6. pauseVideo()

  7. stopVideo()

  8. clearVideo()

  9. getVideoBytesLoaded()

  10. getVideoBytesTotal()

  11. getVideoLoadedFraction()

  12. getVideoStartBytes()

  13. cuePlaylist()

  14. loadPlaylist()

  15. nextVideo()

  16. previousVideo()

  17. playVideoAt()

  18. setShuffle()

  19. setLoop()

  20. getPlaylist()

  21. getPlaylistIndex()

  22. getPlaylistId()

  23. loadModule()

  24. unloadModule()

  25. setOption()

  26. getOption()

  27. getOptions()

  28. mute()

  29. unMute()

  30. isMuted()

  31. setVolume()

  32. getVolume()

  33. seekTo()

  34. getPlayerState()

  35. getPlaybackRate()

  36. setPlaybackRate()

  37. getAvailablePlaybackRates()

  38. getPlaybackQuality()

  39. setPlaybackQuality()

  40. getAvailableQualityLevels()

  41. getCurrentTime()

  42. getDuration()

  43. addEventListener()

  44. removeEventListener()

  45. getDebugText()

  46. getVideoData()

  47. addCueRange()

  48. removeCueRange()

  49. setSize()

  50. getApiInterface()

  51. destroy()

  52. showVideoInfo()

  53. hideVideoInfo()

  54. isVideoInfoVisible()

  55. getSphericalProperties()

  56. setSphericalProperties()

  57. getVideoEmbedCode()

  58. getVideoUrl()

  59. getMediaReferenceTime()

  60. getInternalApiInterface()

  61. cueVideoByPlayerVars()

  62. loadVideoByPlayerVars()

  63. preloadVideoByPlayerVars()

  64. getAdState()

  65. sendAbandonmentPing()

  66. setLoopRange()

  67. getLoopRange()

  68. setAutonavState()

  69. seekToLiveHead()

  70. seekToStreamTime()

  71. seekToChapterWithAnimation()

  72. startSeekCsiAction()

  73. getStreamTimeOffset()

  74. setIsExternalPlaylist()

  75. downloadVideo()

  76. refreshAllVideos()

  77. deleteVideos()

  78. deleteAllVideos()

  79. isOrchestrationLeader()

  80. getAppState()

  81. addInfoCardXml()

  82. updateLastActiveTime()

  83. setBlackout()

  84. setAccountLinkState()

  85. updateAccountLinkingConfig()

  86. setUserEngagement()

  87. updateSubtitlesUserSettings()

  88. setFauxFullscreen()

  89. setUseFastSizingOnWatch()

  90. getPresentingPlayerType()

  91. canPlayType()

  92. updatePlaylist()

  93. updateVideoData()

  94. updateEnvironmentData()

  95. sendVideoStatsEngageEvent()

  96. setCardsVisible()

  97. productsInVideoVisibilityUpdated()

  98. setSafetyMode()

  99. isAtLiveHead()

  100. getVideoAspectRatio()

  101. getPreferredQuality()

  102. setPlaybackQualityRange()

  103. onAdUxClicked()

  104. getFeedbackProductData()

  105. getStoryboardFrame()

  106. getStoryboardFrameIndex()

  107. getStoryboardLevel()

  108. getNumberOfStoryboardLevels()

  109. getCaptionWindowContainerId()

  110. getAvailableQualityLabels()

  111. setAutonav()

  112. isNotServable()

  113. channelSubscribed()

  114. channelUnsubscribed()

  115. isPictureInPictureAllowed()

  116. togglePictureInPicture()

  117. supportsGaplessAudio()

  118. enqueueVideoByPlayerVars()

  119. clearQueue()

  120. isFastLoad()

  121. getPlayerResponse()

  122. getAudioTrack()

  123. setAudioTrack()

  124. getAvailableAudioTracks()

  125. getMaxPlaybackQuality()

  126. getUserPlaybackQualityPreference()

  127. getSubtitlesUserSettings()

  128. resetSubtitlesUserSettings()

  129. setMinimized()

  130. confirmYpcRental()

  131. setInlinePreview()

  132. toggleSubtitlesOn()

  133. handleExternalCall()

  134. isExternalMethodAvailable()

  135. getStatsForNerds()

  136. setScreenLayer()

  137. getCurrentPlaylistSequence()

  138. getPlaylistSequenceForTime()

  139. shouldSendVisibilityState()

  140. updateFullerscreenEduButtonVisibility()

  141. updateFullerscreenEduButtonSubtleModeState()

  142. setGlobalCrop()

  143. getVisibilityState()

  144. isMutedByMutedAutoplay()

  145. setInternalSize()

  146. seekBy()

  147. mutedAutoplay()

  148. showControls()

  149. hideControls()

  150. cancelPlayback()

  151. getProgressState()

  152. isInline()

  153. setInline()

  154. getStoryboardFormat()

  155. getVideoContentRect()

  156. toggleFullscreen()

  157. isFullscreen()

  158. getVideoStats()

  159. getPlayerSize()

  160. toggleSubtitles()

  161. setCenterCrop()

  162. handleGlobalKeyDown()

  163. handleGlobalKeyUp()

  164. setSizeStyle()

  165. wakeUpControls()

@tqk2811
Copy link

tqk2811 commented Jun 20, 2021

How to stop autoplay next video in youtube? (turn off "auto play")
I was try but not work

$("#movie_player").setAutonav(false);
$("#movie_player").setAutonavState(false);
$("#movie_player").setAutonav(0);
$("#movie_player").setAutonavState(0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment