YouTube MP3

FREEMIUM
Door ytjar | Bijgewerkt 13 days ago | Tools
Populariteit

9.9 / 10

Latency

345ms

Serviceniveau

100%

Terug naar alle tutorials (2)

How to handle 'processing' status

Video to Mp3 conversion takes some time and for the same reason API returns processing status if the video is being converted to MP3 so that client need not to wait longer for response as the conversion depends on the length of the video and several other factors.

So upon receiving processing status, a new request should be made to API for the response and it should be repeated until the received status is concluding like ok or fail

For example in JS:

function mp3Conversion(id){
	const settings = {
		"async": true,
		"crossDomain": true,
		"url": "https://youtube-mp36.p.rapidapi.com/dl?id=" + id,
		"method": "GET",
		"headers": {
			"x-rapidapi-key": "Your_API_Key",
			"x-rapidapi-host": "youtube-mp36.p.rapidapi.com"
		}
	};

	$.ajax(settings).done(function (response) {		
		if (response.status == "processing"){
			setTimeout(function(){
				mp3Conversion(id);
			}, 1000);
		} else {
			console.log(response);
		}
	});
}

For quota calculation, only ‘ok’ status calls is considered, so ‘processing’ status calls does not cost any quota.

Beoordeling: 4.2 - Stemmen: 10