Youtube APIs not working with sound.PlayURL()?

-snip-

The link has to be to a direct mp3, wav, or ogg file, not to a download page.

Is there a way to convert this to a direct link?

Actually download the video’s mp3 and put it on Google Drive or something. I think Google Drive has direct links if you get the right URL.

[editline]1st November 2017[/editline]

it doesn’t seem to actually. damn it

Is the information on this thread incorrect then?

I guess it must actually work. I think what code_gs actually meant is instead of the URL you are going to:
http://www.convertmp3.io/fetch/?format=JSON&video=https://www.youtube.com/watch?v=i62Zjga8JOM
You need to use the actual direct URL on that page:
http://www.convertmp3.io//download//get//?i=g0ETatGSDeskZg2DHmCQbA9Vf1u2GbrG&e=83

This is my Google Drive link that I was trying to get to end with .mp3 by the way:
https://drive.google.com/uc?export=download&id=0B1wk-W8v4PrgMV96NGthci1CaVE
That might work as well (maybe)…

EDIT: sorry, I’m really dumb. I didn’t see that was what you were already doing.

That’s what I am using, I’m getting the ‘link’ value from the JSON in the first link which contains the second link

Guess you can’t play from the API link directly so you should download the file with http.Fetch and play it with sound.PlayFile. Here’s a working example:

[lua]
http.Fetch(“http://www.convertmp3.io/fetch/?format=JSON&video=https://www.youtube.com/watch?v=K0nsmdGKf48&start=0&end=15”, function(body)
local json = util.JSONToTable(body)

print("Downloading")
http.Fetch(json.link, function(data)
	print("Downloaded")
	file.Write("stuff.dat", data)

	sound.PlayFile("data/stuff.dat", "noblock", function(station, ...)
		if (IsValid(station)) then
			print("Playing")
			station:Play()

			timer.Simple(station:GetLength(), function()
				print("Deleted")
				file.Delete("stuff.dat")
			end)
		else
			print("Failed to play", ...)
		end
	end)
end)

end)
[/lua]

[editline]1st November 2017[/editline]

Although this API seems really finicky so sometimes this code will not work.

Was hoping I wouldn’t have to do that. Thanks though.

You could always just use an invisible Awesomium panel embedding the video.

You can’t change the volume of it though, right?

Afaik youtube videos don’t have anything to change/force the volume (because of obvious reasons).
Last time I looked this up was about 3 months ago.

[editline]2nd November 2017[/editline]

Why obvious reasons? Garry’s Mod doesn’t let you change the system volume for obvious reasons, but YouTube’s volume can’t do any harm.
The worst it can do is play at 100% volume, which shouldn’t surprise you if your system volume is already way up.

Using Awesomium can be quite unstable, especially on YouTube.

For my radio addon I used the convertmp3.io / YoutubeInMP3.com API for like 2 years by now but it seemed getting more and more unreliable even with using a clientside cache.

I noticed that videos that haven’t been converted recently by manually clicking the “Download” button will not give a working download URL.

In the past I got more and more reports of these “yt not work, fix it” in the comments to that point that I have gave up supporting YouTube in this addon.
I probably will remove it soon, also because making people read (in-game) helps and instruction next to the error display for the required manual step is not possible.
By the way I was recently told that the API is indeed somehow broken. Atleast it is for some users of this addon, including me.

So I think you do yourself favor by avoiding that YouTube thing unless you are willing to set up you own converting server or something.

My bad I forgot I was mentioning just basic iframes with no javascript.

Obvious reasons being setting the volume to a song to ear rape people with. My headset is constantly on 28% volume but 100% youtube volume gets loud as fuck if it’s not from like 2013.