Skip to content

Commit

Permalink
Update nf_rating.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yichahucha authored Jul 1, 2020
1 parent 18aaab6 commit 8483777
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions nf_rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,46 @@ if (!$tool.isResponse) {
if (!IMDbApikey) updateIMDbApikey();
let obj = JSON.parse($response.body);
if (consoleLog) console.log("Netflix Original Body:\n" + $response.body);
if (typeof(obj.paths[0][1]) == "string") {
const videoID = obj.paths[0][1];
const video = obj.value.videos[videoID];
const map = getTitleMap();
let title = map[videoID];
if (!title) {
title = video.summary.title;
setTitleMap(videoID, title, map);
}
let year = null;
let type = video.summary.type;
if (type == "show") {
type = "series";
}
if (type == "movie") {
year = video.details.releaseYear;
}
delete video.details;
const requestRatings = async () => {
const IMDb = await requestIMDbRating(title, year, type);
const Douban = await requestDoubanRating(IMDb.id);
const IMDbrating = IMDb.msg.rating;
const tomatoes = IMDb.msg.tomatoes;
const country = IMDb.msg.country;
const doubanRating = Douban.rating;
const message = `${country}\n${IMDbrating}\n${doubanRating}${tomatoes.length > 0 ? "\n" + tomatoes + "\n" : "\n"}`;
return message;
}
let msg = "";
requestRatings()
.then(message => msg = message)
.catch(error => msg = error + "\n")
.finally(() => {
let summary = obj.value.videos[videoID].summary;
summary["supplementalMessage"] = `${msg}${summary && summary.supplementalMessage ? "\n" + summary.supplementalMessage : ""}`;
if (consoleLog) console.log("Netflix Modified Body:\n" + JSON.stringify(obj));
$done({ body: JSON.stringify(obj) });
});
if (typeof (obj.paths[0][1]) == "string") {
const videoID = obj.paths[0][1];
const video = obj.value.videos[videoID];
const map = getTitleMap();
let title = map[videoID];
if (!title) {
title = video.summary.title;
setTitleMap(videoID, title, map);
}
let year = null;
let type = video.summary.type;
if (type == "show") {
type = "series";
}
if (video.details) {
if (type == "movie") {
year = video.details.releaseYear;
}
delete video.details;
}
const requestRatings = async () => {
const IMDb = await requestIMDbRating(title, year, type);
const Douban = await requestDoubanRating(IMDb.id);
const IMDbrating = IMDb.msg.rating;
const tomatoes = IMDb.msg.tomatoes;
const country = IMDb.msg.country;
const doubanRating = Douban.rating;
const message = `${country}\n${IMDbrating}\n${doubanRating}${tomatoes.length > 0 ? "\n" + tomatoes + "\n" : "\n"}`;
return message;
}
let msg = "";
requestRatings()
.then(message => msg = message)
.catch(error => msg = error + "\n")
.finally(() => {
let summary = obj.value.videos[videoID].summary;
summary["supplementalMessage"] = `${msg}${summary && summary.supplementalMessage ? "\n" + summary.supplementalMessage : ""}`;
if (consoleLog) console.log("Netflix Modified Body:\n" + JSON.stringify(obj));
$done({ body: JSON.stringify(obj) });
});
} else {
$done({});
}
Expand Down

0 comments on commit 8483777

Please sign in to comment.