function getTrack(id) {
var getParams = {
audios: id,
access_token: '***'
};
$.getJSON('https://api.vk.com/method/audio.getById', getParams, function (json) {
if (json.error !== undefined) {
var errorCode = json.error.error_code;
if (errorCode == 14) {
console.log('Captcha!');
} else if (errorCode == 6) {
console.log('Too many requests! Try again.');
return getTrack(id);
}
} else {
console.log(json.response['0']);
return json.response['0'];
}
});
}
$(function () {
$('.play , .download').click(function () {
var trackItem = $(this).parent('.track'),
trackId = trackItem.attr('data-id');
if (trackItem.attr('data-url') !== undefined) {
} else {
console.log(getTrack(trackId));
}
});
});
function getTrack(id,cb) {
var getParams = {
audios: id,
access_token: '***'
};
$.getJSON('https://api.vk.com/method/audio.getById', getParams, function (json) {
if (json.error !== undefined) {
var errorCode = json.error.error_code;
if (errorCode == 14) {
console.log('Captcha!');
} else if (errorCode == 6) {
console.log('Too many requests! Try again.');
return getTrack(id);
}
} else {
cb(json.response['0']);
}
});
}
$('.play , .download').click(function () {
var trackItem = $(this).parent('.track'),
trackId = trackItem.attr('data-id');
if (trackItem.attr('data-url') !== undefined) {
} else {
getTrack( trackId, function (id) {
console.log(id);
});
}
});