YouTube MP3

부분 유료
분류별 ytjar | 업데이트됨 לפני חודש | Tools
인기

9.9 / 10

지연 시간

396ms

서비스 수준

100%

Health Check

100%

모든 자습서로 돌아가기 (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.