From 0f2fa698ec39c8f2279b0ceae9e9df606268b82d Mon Sep 17 00:00:00 2001 From: Marvin Alexander Krebber Date: Thu, 26 Oct 2023 16:46:36 +0200 Subject: [PATCH] replaced justwatch with themoviedb --- chrome/badge.js | 5 +++- chrome/skipper.js | 52 +++++++++++++++++++++------------ firefox/badge.js | 5 +++- firefox/skipper.js | 72 ++++++++++++++++++++++++++-------------------- 4 files changed, 82 insertions(+), 52 deletions(-) diff --git a/chrome/badge.js b/chrome/badge.js index c47c426e..604141e3 100644 --- a/chrome/badge.js +++ b/chrome/badge.js @@ -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()) diff --git a/chrome/skipper.js b/chrome/skipper.js index 1d36a208..29b05f1e 100644 --- a/chrome/skipper.js +++ b/chrome/skipper.js @@ -120,6 +120,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) { } else if (isPrimeVideo) { if (settings.Amazon?.streamLinks) addStreamLinks(); } else if (isDisney || isHotstar) { + // startShowRatingInterval(); } }); }); @@ -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 { @@ -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")) { @@ -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"); @@ -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); } diff --git a/firefox/badge.js b/firefox/badge.js index 68a3caf0..5286e34e 100644 --- a/firefox/badge.js +++ b/firefox/badge.js @@ -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()) diff --git a/firefox/skipper.js b/firefox/skipper.js index cf8823af..06170db3 100644 --- a/firefox/skipper.js +++ b/firefox/skipper.js @@ -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 { @@ -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"); @@ -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);