Answer the question
In order to leave comments, you need to log in
Why doesn't then work?
I'm trying to learn the promises, but it doesn't work. What is the problem?
let getMoviePage = new Promise(function(resolve, reject) {
Request.get(searchParams, (err, res, page) => {
console.log(`movie: ${searchParams.uri}`);
const $ = cheerio.load(page);
resolve($('iframe').attr('src'));
});
});
app.get('/', (request, response) => {
getMoviePage
.then(iframe => {
Request.get(iframe, (err, res, page) => {
console.log(`iframe: ${playlistFrameLink}`);
const $ = cheerio.load(page);
let filePath = $.html();
let playlistLink = Cut(filePath, { fragmentStart: 'var flashvars = ', fragmentEnd: '\'};' });
// delete spaces
playlistLink = playlistLink.replace(/\s+/g, ' ');
//...
return playlistLink;
});
})
.then(playlist => {
console.log(`playlist: ${playlist}`);
Request.get(playlist, (err, res, page) => {
const $ = cheerio.load(page);
return JSON.parse($('body').text());
});
})
.then(playlist => {
console.log(playlist);
//...
response.send(playlistWeight);
})
.catch(err => {
console.error(err);
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question