var options = {
method: 'GET',
uri: 'https://www.kinopoisk.ru/index.php?first=no&what=&kp_query='+encodeURIComponent(filmName),
json: true
};
rp(options)
.then(function (htmlString) {
$ = cheerio.load(htmlString);
var poster = $('.most_wanted>.pic>a>img').attr('title');
var title = $('.most_wanted>.info>.name>a').html();
console.log(title );
var filmData = new Array({poster: poster, title: title});
resolve(filmData);
})
.catch(function (err) {
// Crawling failed...
});
return Promise.all(myRequests)
.then((arrayOfHtml) => arrayOfHtml.map(result => result.data))
.then((arrayOfHtml) => {
//Пытаемся получить картинку от ласт фм, если нету, выдаем пустую строку
if(arrayOfHtml[0].results.artistmatches.artist[0]['image'][2]['#text']){
last = arrayOfHtml[0].results.artistmatches.artist[0]['image'][2]['#text'];
}else {
last = false;
}
if(last) {
some();
}
})
.catch(function(e){
//Ловим ошибку
console.log(chalk.red("Ошибка " +e));
});
io.on('connection', function (socket) {
socket.on('songchanged', function(changed){
socket.broadcast.emit('changed', data);
})
})
result.forEach(function(item){
wp.song().search( item['artist']+' - '+item['song'] ).then(function( posts ) {
if(!posts[0]){
var myRequests = [];
myRequests.push(rp({uri: "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+encodeURIComponent(item['artist'])+"&api_key=*****&format=json", json: true}));
myRequests.push(rp({uri: "https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&q="+encodeURIComponent(item['artist']+'+'+item['song'])+"&type=video&key=***", json: true}));
Promise.all(myRequests)
.then((arrayOfHtml) => {
console.log(arrayOfHtml[0]['artist']['image'][2]['#text']);
console.log(arrayOfHtml[1]['items'][0]['id'].videoId);
wp.posts().create({
title: item['artist']+' - '+item['song'],
content: 'Your post content',
status: 'publish'
}).then(function( response ) {
console.log( response.id );
})
})
.catch(/* handle error */);
}
});
})`
request.get("https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&q="+result[k]['song']+'+'+result[k]['song']+"&type=video&key=AIzaSyAvDAdEnqrStOJNnpnGy9BkrC_sG-gcHIU", function(err,res,body){
if(res.statusCode == 200 ) {
var c = JSON.parse(body);
console.log(c['items'][0]['id']['videoId']);
}
});