YouTube MP3

FREEMIUM
Par ytjar | Mise à jour 5 days ago | Tools
Popularité

9.9 / 10

Latence

492ms

Niveau de service

100%

Health Check

100%

Retour à tous les tutoriels (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.