Skip to content

Instantly share code, notes, and snippets.

@FevenKitsune
Created October 15, 2022 00:06
Show Gist options
  • Select an option

  • Save FevenKitsune/ec0c90bd53b86fb1e77602c4af5896fe to your computer and use it in GitHub Desktop.

Select an option

Save FevenKitsune/ec0c90bd53b86fb1e77602c4af5896fe to your computer and use it in GitHub Desktop.
@name Music Player
@persist Prefix:string Queue:array Video:video Audio:webaudio CurrentlyPlaying
@trigger none
if(first()|dupefinished()){
Prefix = "??"
function void updateName() {
if(Queue:count() > 0) {
setName("Music Player\n\nCurrently Playing:\n" + Video:title() + "\nQueue:\n" + Queue:concat("\n"))
}
else {
setName("Music Player\n\nCurrently Playing:\n" + Video:title() + "\nQueue:\n")
}
}
function void playNext() {
if(Queue:count() > 0) {
CurrentlyPlaying = 1
local Request = Queue:shiftString()
youtubeSearch(httpUrlEncode(Request))
}
}
runOnChat(1)
runOnYoutube(1)
timer("updateName", 1000)
}
elseif(chatClk()) {
local Msg = lastSaid()
local Ply = lastSpoke()
local Args = Msg:explode(" ")
local Cmd = Args:removeString(1)
if(Cmd:sub(0, Prefix:length())) {
local PRFX = Cmd:sub(0, Prefix:length())
if(PRFX == Prefix) { hideChat(1)
local Cmd = Cmd:sub(Prefix:length() + 1)
switch(Cmd:lower()) {
case("play"),
local Request = Args:concat(" ")
Queue:pushString(Request)
if(!CurrentlyPlaying) {
playNext()
}
break
case("skip"),
if(Audio:isValid()) {
stoptimer("nextSong")
Audio:destroy()
playNext()
}
break
}
}
}
}
elseif(youtubeClk()) {
if(isYoutubeSearch()) {
local Search = youtubeSearchData()
#Get first result of search
local Vid = Search:first()
#Create url using youtube hash of the video
local URL = "https://www.youtube.com/watch?v=" + Vid["id", string]
#Request url
youtubeRequest(URL)
}
else {
Video = youtubeData()
print(Video:title())
#Create webAudio object from mp3 link
Audio = webAudio(Video:mp3())
#Set position and play
Audio:setParent(entity())
Audio:setVolume(200)
Audio:setRadius(500)
Audio:play()
timer("nextSong", Video:duration())
}
}
elseif(clk("nextSong")) {
Audio:destroy()
Audio = nowebaudio() #Makes the webaudio:isDone function return true due to it being invalid
CurrentlyPlaying = 0
playNext()
}
elseif(clk("updateName")) {
updateName()
timer("updateName", 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment