MCPcopy Create free account
hub / github.com/NobyDa/Script / requestIMDbRating

Function requestIMDbRating

Disney/DisneyRating.js:85–118  ·  view source on GitHub ↗
(title, year, type)

Source from the content-addressed store, hash-verified

83}
84
85function 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
120function updateIMDbApikey() {
121 if (IMDbApikey) IMDbApikeys.splice(IMDbApikeys.indexOf(IMDbApikey), 1);

Callers 1

requestRatingsFunction · 0.85

Calls 4

get_IMDb_messageFunction · 0.85
updateIMDbApikeyFunction · 0.85
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected