Skip to content

Commit

Permalink
replaced justwatch with themoviedb
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamlinerm committed Oct 26, 2023
1 parent 604017a commit 0f2fa69
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 52 deletions.
5 changes: 4 additions & 1 deletion chrome/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
fetch(message.url, {
method: "GET",
headers: {
Accept: "application/json",
accept: "application/json",
// api key for themoviedb
Authorization:
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI5OWQyMWUxMmYzNjU1MjM4NzdhNTAwODVhMmVjYThiZiIsInN1YiI6IjY1M2E3Mjg3MjgxMWExMDBlYTA4NjI5OCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.x_EaVXQkg1_plk0NVSBnoNUl4QlGytdeO613nXIsP3w",
},
})
.then((response) => response.json())
Expand Down
52 changes: 33 additions & 19 deletions chrome/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
} else if (isPrimeVideo) {
if (settings.Amazon?.streamLinks) addStreamLinks();
} else if (isDisney || isHotstar) {
// startShowRatingInterval();
}
});
});
Expand Down Expand Up @@ -205,26 +206,35 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
}
}
// justWatchAPI
async function getMovieInfo(title, card, Rating = true, locale = "en_US") {
async function getMovieInfo(title, card, Rating = true, locale = "en-US") {
// console.log("getMovieInfo", movieTitle);
const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
// justwatch api
// const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
// use the url for themoviedb.org now
const url = `https://api.themoviedb.org/3/search/movie?query=${encodeURI(title)}&include_adult=true&language=${locale}&page=1`;
// const response = await fetch(encodeURI(url));
// const data = await response.json();

chrome.runtime.sendMessage({ url }, function (data) {
if (data != undefined && data != "") {
// "https://www.justwatch.com" + data.items[0].full_path;
const jWURL = data?.items?.[0]?.full_path;
// flatrate = free with subscription
// (netflix, amazon prime, disney+) (x.package_short_name == "amp" || x.package_short_name == "nfx" || x.package_short_name == "dnp")
// fuv and drv are both hulu
let offers = data?.items?.[0].offers?.filter((x) => x.monetization_type == "flatrate");
// get the first offer of each provider
offers = offers?.filter((x, i) => offers.findIndex((y) => y.provider_id == x.provider_id) == i);
// map offers to only package_short_name, country and standard_web url
offers = offers?.map((x) => ({ country: x.country, package_short_name: x.package_short_name, url: x.urls.standard_web }));
const score = data?.items?.[0]?.scoring?.filter((x) => x.provider_type == "imdb:score")?.[0]?.value;
const compiledData = { jWURL, score, streamLinks: offers };
// // justwatch
// // "https://www.justwatch.com" + data.items[0].full_path;
// const jWURL = data?.items?.[0]?.full_path;
// // flatrate = free with subscription
// // (netflix, amazon prime, disney+) (x.package_short_name == "amp" || x.package_short_name == "nfx" || x.package_short_name == "dnp")
// // fuv and drv are both hulu
// let offers = data?.items?.[0].offers?.filter((x) => x.monetization_type == "flatrate");
// // get the first offer of each provider
// offers = offers?.filter((x, i) => offers.findIndex((y) => y.provider_id == x.provider_id) == i);
// // map offers to only package_short_name, country and standard_web url
// offers = offers?.map((x) => ({ country: x.country, package_short_name: x.package_short_name, url: x.urls.standard_web }));
// const score = data?.items?.[0]?.scoring?.filter((x) => x.provider_type == "imdb:score")?.[0]?.value;
// const compiledData = { jWURL, score, streamLinks: offers };

// themoviedb
if (!data?.results?.[0]) {
console.log("no data found", data);
}
const compiledData = { score: data?.results?.[0]?.vote_average };
DBCache[title] = compiledData;
if (Rating) setRatingOnCard(card, compiledData, title);
else {
Expand All @@ -243,12 +253,15 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
async function JustWatch() {
let titleCards;
if (isNetflix) titleCards = document.querySelectorAll(".title-card .boxart-container:not(.imdb)");
else if (isDisney) titleCards = document.querySelectorAll(".basic-card div div img:not(.imdb)");
// amazon
else titleCards = document.querySelectorAll("li:not(.imdb) [data-card-title]");
titleCards.forEach((card) => {
// let card = document.querySelector("li:not(.imdb) [data-card-title]");
// let card = document.querySelector(".title-card .boxart-container:not(.imdb)");
// let card = document.querySelectorAll(".title-card .boxart-container:not(.imdb)");
let title;
if (isNetflix) title = card?.children?.[1]?.firstChild?.textContent;
else if (isDisney) title = card?.getAttribute("alt");
// amazon
// remove everything after - in the title
else title = card.getAttribute("data-card-title").split(" - ")[0].split(" – ")[0]; //Amazon
if (title && !title.includes("Netflix") && !title.includes("Prime Video")) {
Expand Down Expand Up @@ -347,7 +360,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
}

async function setRatingOnCard(card, data, title) {
if (isNetflix) card.classList.add("imdb");
if (isNetflix || isDisney) card.classList.add("imdb");
else card.parentElement.classList.add("imdb");

let div = document.createElement("div");
Expand All @@ -359,9 +372,10 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
// div.textContent = title;
} else {
div.textContent = "?";
console.log("no Score found", title);
console.log("no Score found", title, data);
}
if (isNetflix) card.appendChild(div);
else if (isDisney) card.parentElement.appendChild(div);
else card.firstChild.firstChild.appendChild(div);
}

Expand Down
5 changes: 4 additions & 1 deletion firefox/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ browser.runtime.onMessage.addListener(function (message, sender, sendResponse) {
fetch(message.url, {
method: "GET",
headers: {
Accept: "application/json",
accept: "application/json",
// api key for themoviedb
Authorization:
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI5OWQyMWUxMmYzNjU1MjM4NzdhNTAwODVhMmVjYThiZiIsInN1YiI6IjY1M2E3Mjg3MjgxMWExMDBlYTA4NjI5OCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.x_EaVXQkg1_plk0NVSBnoNUl4QlGytdeO613nXIsP3w",
},
})
.then((response) => response.json())
Expand Down
72 changes: 41 additions & 31 deletions firefox/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,35 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
}
}
// justWatchAPI
async function getMovieInfo(title, card, Rating = true, locale = "en_US") {
async function getMovieInfo(title, card, Rating = true, locale = "en-US") {
// console.log("getMovieInfo", movieTitle);
const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
// justwatch api
// const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
// use the url for themoviedb.org now
const url = `https://api.themoviedb.org/3/search/movie?query=${encodeURI(title)}&include_adult=true&language=${locale}&page=1`;
// const response = await fetch(encodeURI(url));
// const data = await response.json();
browser.runtime.sendMessage({ url }, function (data) {
if (data != undefined && data != "") {
// "https://www.justwatch.com" + data.items[0].full_path;
const jWURL = data?.items?.[0]?.full_path;
// flatrate = free with subscription
// (netflix, amazon prime, disney+) (x.package_short_name == "amp" || x.package_short_name == "nfx" || x.package_short_name == "dnp")
// fuv and drv are both hulu
let offers = data?.items?.[0].offers?.filter((x) => x.monetization_type == "flatrate");
// get the first offer of each provider
offers = offers?.filter((x, i) => offers.findIndex((y) => y.provider_id == x.provider_id) == i);
// map offers to only package_short_name, country and standard_web url
offers = offers?.map((x) => ({ country: x.country, package_short_name: x.package_short_name, url: x.urls.standard_web }));
const score = data?.items?.[0]?.scoring?.filter((x) => x.provider_type == "imdb:score")?.[0]?.value;
const compiledData = { jWURL, score, streamLinks: offers };
// // justwatch
// // "https://www.justwatch.com" + data.items[0].full_path;
// const jWURL = data?.items?.[0]?.full_path;
// // flatrate = free with subscription
// // (netflix, amazon prime, disney+) (x.package_short_name == "amp" || x.package_short_name == "nfx" || x.package_short_name == "dnp")
// // fuv and drv are both hulu
// let offers = data?.items?.[0].offers?.filter((x) => x.monetization_type == "flatrate");
// // get the first offer of each provider
// offers = offers?.filter((x, i) => offers.findIndex((y) => y.provider_id == x.provider_id) == i);
// // map offers to only package_short_name, country and standard_web url
// offers = offers?.map((x) => ({ country: x.country, package_short_name: x.package_short_name, url: x.urls.standard_web }));
// const score = data?.items?.[0]?.scoring?.filter((x) => x.provider_type == "imdb:score")?.[0]?.value;
// const compiledData = { jWURL, score, streamLinks: offers };

// themoviedb
if (!data?.results?.[0]) {
console.log("no data found", data);
}
const compiledData = { score: data?.results?.[0]?.vote_average };
DBCache[title] = compiledData;
if (Rating) setRatingOnCard(card, compiledData, title);
else {
Expand All @@ -246,23 +256,23 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
else if (isDisney) titleCards = document.querySelectorAll(".basic-card div div img:not(.imdb)");
// amazon
else titleCards = document.querySelectorAll("li:not(.imdb) [data-card-title]");
// titleCards.forEach((card) => {
let card = document.querySelector(".basic-card div div img:not(.imdb)");
let title;
if (isNetflix) title = card?.children?.[1]?.firstChild?.textContent;
else if (isDisney) title = card?.getAttribute("alt");
// amazon
// remove everything after - in the title
else title = card.getAttribute("data-card-title").split(" - ")[0].split(" – ")[0]; //Amazon
if (title && !title.includes("Netflix") && !title.includes("Prime Video")) {
if (!DBCache[title]) {
getMovieInfo(title, card);
log("no info in DBcache", title);
} else {
setRatingOnCard(card, DBCache[title], title);
titleCards.forEach((card) => {
// let card = document.querySelectorAll(".title-card .boxart-container:not(.imdb)");
let title;
if (isNetflix) title = card?.children?.[1]?.firstChild?.textContent;
else if (isDisney) title = card?.getAttribute("alt");
// amazon
// remove everything after - in the title
else title = card.getAttribute("data-card-title").split(" - ")[0].split(" – ")[0]; //Amazon
if (title && !title.includes("Netflix") && !title.includes("Prime Video")) {
if (!DBCache[title]) {
getMovieInfo(title, card);
log("no info in DBcache", title);
} else {
setRatingOnCard(card, DBCache[title], title);
}
}
}
// });
});
}
async function setAlternativesOnCard(card, data) {
let div = document.createElement("div");
Expand Down Expand Up @@ -362,7 +372,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
// div.textContent = title;
} else {
div.textContent = "?";
console.log("no Score found", title);
console.log("no Score found", title, data);
}
if (isNetflix) card.appendChild(div);
else if (isDisney) card.parentElement.appendChild(div);
Expand Down

0 comments on commit 0f2fa69

Please sign in to comment.