Jump to content

[Help] Sound Fetch from YouTube


Looney;3

Recommended Posts

link = "https://www.youtube.com/watch?v=WAT47vPfs04"
function onResourceStart()
		playingSound = playSound("http://www.convertmp3.io/fetch/?video="..link)
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onResourceStart)

why don't work this?

Link to post

It's a little bit more complicated than this.

You will need to use fetchRemote which means you need to whitelist the domain "www.convertmp3.io" with requestBrowserDomains to use their json/xml api to the bottom of the page.

When you use the fetchRemote function your response data will be of the format specified and will need to extract the direct link and use that to play the sound with playSound.

I've used this api before and some youtube links will not work unless they have special tags indicating that the video is a song.

  • Like 1
Link to post
15 hours ago, Mr.Loki said:

It's a little bit more complicated than this.

You will need to use fetchRemote which means you need to whitelist the domain "www.convertmp3.io" with requestBrowserDomains to use their json/xml api to the bottom of the page.

When you use the fetchRemote function your response data will be of the format specified and will need to extract the direct link and use that to play the sound with playSound.

I've used this api before and some youtube links will not work unless they have special tags indicating that the video is a song.

Thanks
but now fetchRemote send error #1006

  • 1006: Destination IP not allowed 

u know why?

Link to post

I think that's because you didn't whitelist the domain properly.

Go to settings > Web Browser > Custom Whitelist and see if there is " www.convertmp3.io" ls listed there.

Edited by Mr.Loki
Link to post
3 minutes ago, Mr.Loki said:

Creo que es porque no incluiste en la lista blanca el dominio correctamente.

Vaya a la configuración> Navegador web> Lista blanca personalizada y vea si allí se encuentra "www.convertmp3.io".

Joj9Cah.jpg
 

Link to post

I'm glad i saw this topic because i figured out a bypass to get the links to work.

It was not working before because javascript redirects you to the download link after a few seconds to stop bots from using the site :P

So here it is and i can finally fix a music player script i got :D

I don't know how long this will last but there will be a possibility that this will break and this code needs some optimizations.

requestBrowserDomains({"www.convertmp3.io"})
local browser = createBrowser( 0, 0, false )
local currentSound

function start(_,link)
    fetch(link)
end
addCommandHandler("play",start)

function fetch(url)
    if (url) then
        fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback)
    end
end

function callback(data, error)
    if (error ~= 0) then
        return outputChatBox(error)
    end
    if (data == "ERROR") then
        return outputChatBox("data error")
    end
    local data = fromJSON("["..data.."]")
    if (data) then
        outputChatBox("Title: "..data.title)
        outputChatBox("Length: "..data.length)
        outputChatBox("Link: "..data.link)
        loadBrowserURL( browser, data.link  )
    end
end

addEventHandler( "onClientBrowserNavigate", browser, function( link )
        if not link:find("www.convertmp3.io") then
            currentSound = playSound( link )
        end
    end 
)

This creates a dummy browser and waits for the redirect link to play the sound.

  • Like 2
  • Thanks 2
Link to post
On 18/7/2018 at 2:12 PM, Mr.Loki said:

I'm glad i saw this topic because i figured out a bypass to get the links to work.

It was not working before because javascript redirects you to the download link after a few seconds to stop bots from using the site :P

So here it is and i can finally fix a music player script i got :D

I don't know how long this will last but there will be a possibility that this will break and this code needs some optimizations.


requestBrowserDomains({"www.convertmp3.io"})
local browser = createBrowser( 0, 0, false )
local currentSound

function start(_,link)
    fetch(link)
end
addCommandHandler("play",start)

function fetch(url)
    if (url) then
        fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback)
    end
end

function callback(data, error)
    if (error ~= 0) then
        return outputChatBox(error)
    end
    if (data == "ERROR") then
        return outputChatBox("data error")
    end
    local data = fromJSON("["..data.."]")
    if (data) then
        outputChatBox("Title: "..data.title)
        outputChatBox("Length: "..data.length)
        outputChatBox("Link: "..data.link)
        loadBrowserURL( browser, data.link  )
    end
end

addEventHandler( "onClientBrowserNavigate", browser, function( link )
        if not link:find("www.convertmp3.io") then
            currentSound = playSound( link )
        end
    end 
)

This creates a dummy browser and waits for the redirect link to play the sound.

wow thanks bro, but why that will break? :C

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...