• playing a youtube song
    10 replies, posted
Hey guys. How the can I make a lua script that reads a youtube link, and starts playing the link? I'll need to 'collect' the youtube music data some how..
The [url=https://developers.google.com/youtube/getting_started#data_api]YouTube Data API[/url] can be used to grab the metadata of YouTube videos.
you can use http.Fetch to parse a url from [url]http://youtubeinmp3.com/api/[/url] (check the advanced API section) and get an mp3 link that you can play with sound.PlayURL You get the Title, Duration and mp3 link in JSON or Plaintext format.
emm it doesn't exist for lua :S
http.Fetch [url]http://wiki.garrysmod.com/page/http/Fetch‎[/url] sound.PlayUrl [url]http://wiki.garrysmod.com/page/sound/PlayURL[/url] util.JSONToTable [url]http://wiki.garrysmod.com/page/util/JSONToTable[/url] Yes it does.
[QUOTE=Arizard;44665369]you can use http.Fetch to parse a url from [url]http://youtubeinmp3.com/api/[/url] (check the advanced API section) and get an mp3 link that you can play with sound.PlayURL You get the Title, Duration and mp3 link in JSON or Plaintext format.[/QUOTE] So just to do: [url]http://YoutubeInMP3.com/fetch/?api=advanced&video=VIDELOLINK[/url].. And then how do i get the mp3 link? i didn't quite get that.
1. Fetch the JSON link 2. Convert the returned data from JSON into a table 3. The data you want is the table[1]["link"] value 4. use sound.PlayURL to play the mp3 link from table[1]["link"]
[QUOTE=Arizard;44665396]1. Fetch the JSON link 2. Convert the returned data from JSON into a table 3. The data you want is the table[1]["link"] value 4. use sound.PlayURL to play the mp3 link from table[1]["link"][/QUOTE] sorry for being such a noob, how will I convert the JSON to a table? And thanks for helping me ^^.
util.JSONToTable [url]http://wiki.garrysmod.com/page/util/JSONToTable[/url]
P.S. I just found out that sometimes, sound.PlayURL will time out if youtubeinmp3 takes too long to respond to the mp3 link. To solve this, wrap the sound.playurl in http.Fetch, and fetch for the same link. This will wait for youtubeinmp3 to respond before attempting to play the link.
Hello i have tried doing this but the URL doesn't seem to work the one on the JSON [editline]8th August 2017[/editline] As this does download the file it doesn't have the .mp3 and it just breaks. Do you have any alternatives? [highlight](User was banned for this post ("Dumb bump - 3 year old thread m8" - Reagy))[/highlight]
Sorry, you need to Log In to post a reply to this thread.