Hey,
thanks for the API. Works great! Unless it doesn’t work. For example if the input isn’t a proper YouTube url or something else is wrong. Is there any designated way to handle this? Do we need to check the validity of the user input on the client side? Or can we post a request to the API and get a proper error code back in time? Right now it times out after 15 seconds or something.
Cheers,
Tino
Join in the discussion - add comment below:
Hi, you can extract the video ID (id) using JS in the frontend (as you explained), and then, make the request to the API like this:
var url = “https://www.youtube.com/watch?v=”+id;
$.ajax({
url: ‘/YTtomp3_api_endpoint/’,
type: ‘get’,
dataType: ‘JSON’,
data: {url: url},
success: function(response){
//action after success
}
}
Alright. Any plans to implement some sort of early error code response when the API isn’t able to download the video? Right now I’m using this to check for validity on the client side:
The regex comes from this SO answer: https://stackoverflow.com/a/27728417 and supposedly supports 25 different formats of youtube urls. Certainly works, but would of course be nicer if I could outsource all my download related logic to the API 😃
Anyways, thanks for the reply and the api!
Hi, the API validates the Youtube URL & works for these formats:
https://www.youtube.com/watch?v=VnRsoPOwteI
https://www.youtube.com/watch?v=VnRsoPOwteI&list=RDVnRsoPOwteI&start_radio=1&ab_channel=ShivBhakti
https://youtu.be/eCnaaI8FKH4
Means, it suppports YT short links also. You have make sure that the reauest is made in this formats only. if user inputs a URL that diesn’t align with these or have whitespaces, you have to trim the spaces then make the API request. if the URL is altogether not related to YT, API might not reverse a response & run for indefinite time (for now, the TTL is 180 seconds or 5 Mins).