Created
August 3, 2014 20:32
-
-
Save ejb1123/16fb46821be3ec7c333f to your computer and use it in GitHub Desktop.
yify-pop cover image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.getParams = function (params) { | |
var imdb = {}; | |
// Set Defaults | |
imdb.id=''; | |
imdb.cover=''; | |
// Set new parameters | |
if (params) { | |
imdb.id=params; | |
} | |
//console.log(imdb.id); | |
// Set request URL | |
imdb.url = 'http://www.imdbapi.com/?i='; | |
imdb.url += imdb.id; | |
//console.log(imdb.url); | |
var request = require('request'); | |
request(imdb.url, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var imdbResponse = JSON.parse(body); | |
imdb.cover = imdbResponse.Poster; | |
//console.log(imdb.cover); | |
} | |
}) | |
console.log(imdb.cover); | |
return imdb.cover; | |
//console.log(imdb.cover); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.index = function (req, resp, params) { | |
var self = this; | |
var request = require('request'); | |
var baseURL = "http://" + req.headers.host; | |
var yifyRequest = yify.getParams(params, baseURL); | |
request(yifyRequest.url, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var yifyResponse = JSON.parse(body); | |
for(var r = 0;r < yifyResponse.MovieList.length;r++){ | |
var coverImage = imdb.getParams(yifyResponse.MovieList[r].ImdbCode); | |
yifyResponse.MovieList[r].CoverImage = coverImage; | |
} | |
if (yifyResponse.MovieCount < (yify.page * 18)) { | |
nextDisabled = 'disabled'; | |
nextPage = '#'; | |
} | |
self.respond({ | |
params: params, | |
movies: yifyResponse.MovieList, | |
baseURL: baseURL, | |
previousPage: yifyRequest.previousPage, | |
nextPage: yifyRequest.nextPage, | |
previousDisabled: yifyRequest.previousDisabled, | |
nextDisabled: yifyRequest.nextDisabled | |
}, { | |
format: 'html', | |
template: 'app/views/main/index' | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment