(title, year, type)
| 83 | } |
| 84 | |
| 85 | function requestIMDbRating(title, year, type) { |
| 86 | return new Promise(function (resolve, reject) { |
| 87 | let url = "https://www.omdbapi.com/?t=" + encodeURIComponent(title) + "&apikey=" + IMDbApikey; |
| 88 | if (year) url += "&y=" + year; |
| 89 | if (type) url += "&type=" + type; |
| 90 | if (consoleLog) console.log("Disney IMDb Rating URL:\n" + url); |
| 91 | $tool.get(url, function (error, response, data) { |
| 92 | if (!error) { |
| 93 | if (consoleLog) console.log("Disney IMDb Rating Data:\n" + data); |
| 94 | if (response.status == 200) { |
| 95 | const obj = JSON.parse(data); |
| 96 | if (obj.Response == "True") { |
| 97 | const id = obj.imdbID; |
| 98 | const msg = get_IMDb_message(obj); |
| 99 | resolve({ id, msg }); |
| 100 | } else { |
| 101 | reject(`Title [${title}] IMDb data not found`); |
| 102 | } |
| 103 | } else if (response.status == 401) { |
| 104 | if (IMDbApikeys.length > 1) { |
| 105 | updateIMDbApikey(); |
| 106 | requestIMDbRating(title, year, type); |
| 107 | } else { |
| 108 | reject(`IMDb Key invalid`); |
| 109 | } |
| 110 | } else { |
| 111 | reject(`Unknown status: ${response.status}, Data: ${data}`); |
| 112 | } |
| 113 | } else { |
| 114 | reject(`IMDB data response failed: ${error}`); |
| 115 | } |
| 116 | }); |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | function updateIMDbApikey() { |
| 121 | if (IMDbApikey) IMDbApikeys.splice(IMDbApikeys.indexOf(IMDbApikey), 1); |
no test coverage detected