multiwatch/public/index.html

447 lines
44 KiB
HTML
Raw Permalink Normal View History

2020-12-09 22:26:29 +01:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Multiwatch</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<style type="text/css">
body {
max-width: 600px;
margin: auto;
text-align: center;
font-family: sans-serif;
}
h1 a {
text-decoration: none;
color: black;
}
2020-12-12 12:28:54 +01:00
.flex {
display: flex;
flex-wrap: wrap;
}
.flex div {
width: 200px;
text-align: left;
}
2020-12-09 22:26:29 +01:00
.left {
text-align: left;
}
.error {
color: red;
font-weight: bold;
}
.pointer {
cursor: pointer;
}
2020-12-14 20:34:17 +01:00
.poster {
height: 392px;
width: 276px;
display: inline-block;
background-color: gray;
margin: 1em;
}
2020-12-09 22:26:29 +01:00
.no-bullet {
list-style-type: none;
}
</style>
</head>
<body>
<div id="app">
2020-12-12 12:28:54 +01:00
<h1><a href="./index.html">Multiwatch</a></h1>
<p v-if="step > 1"><a href="./index.html">Back</a></p>
2020-12-09 22:26:29 +01:00
<p v-if="error" class="error">{{ error }}</p>
<div v-if="step == 1">
<h2>Search</h2>
<form id="searchForm" v-on:submit.prevent="search">
<p>
<label for="title">Title:</label>
<input type="text" v-model="title" id="title" />
</p>
2020-12-12 12:28:54 +01:00
<h3>Countries</h3>
<div class="flex">
<div v-for="(localeId, country) in availableCountries">
<input type="checkbox" v-bind:id="localeId" v-bind:checked="checkedLocales.indexOf(localeId) !== -1" v-on:click="() => toggleCheckbox(localeId)">
<label v-bind:for="localeId">{{ country }}</label>
</div>
</div>
2020-12-09 22:26:29 +01:00
<p>
<input type="submit" value="Search"/>
</p>
</form>
</div>
2020-12-16 21:11:46 +01:00
<div v-else-if="step == 2">
<ul class="no-bullet">
2020-12-09 22:26:29 +01:00
<li v-for="(item, index) in searchItems">
2020-12-16 21:11:46 +01:00
<img class="pointer poster" v-bind:src="item.poster_url" v-bind:alt="item.title" v-on:click="() => preloadItem(index)" />
2020-12-09 22:26:29 +01:00
</li>
</ul>
2020-12-16 21:11:46 +01:00
</div>
<div v-else-if="step == 3">
<ul class="no-bullet">
<li v-for="(item, index) in seasons">
<img class="pointer poster" v-bind:src="item.poster_url" v-bind:alt="item.title" v-on:click="() => loadItem(index, true)" />
</li>
</ul>
</div>
<div v-else-if="step == 4">
<div v-for="(localeOffers, locale) in offers">
<h3>{{ availableLocales[locale] }}</h3>
<ul v-if="localeOffers.length > 0" class="left">
2024-03-05 11:29:17 +01:00
<li v-for="offer in localeOffers">{{ offer }}</li>
2020-12-16 21:11:46 +01:00
</ul>
<p v-else>None</p>
2020-12-09 22:26:29 +01:00
</div>
</div>
</div>
<script type="text/javascript">
var JUSTWATCH_API_DOMAIN = 'https://apis.justwatch.com';
2020-12-14 20:52:22 +01:00
var checkedLocales = JSON.parse(localStorage.getItem('checkedLocales'));
if (!checkedLocales) {
2024-03-05 11:29:17 +01:00
checkedLocales = ['FR', 'AU', 'CA', 'DE', 'PL', 'SG', 'GB'];
2020-12-14 20:52:22 +01:00
}
2020-12-09 22:26:29 +01:00
var app = new Vue({
el: '#app',
2020-12-12 12:28:54 +01:00
computed: {
availableLocales() {
var out = {};
Object.keys(this.availableCountries).forEach((country) => {
out[this.availableCountries[country]] = country;
});
return out;
},
},
2020-12-09 22:26:29 +01:00
data: {
2020-12-14 20:52:22 +01:00
checkedLocales: checkedLocales,
2020-12-12 12:28:54 +01:00
availableCountries: {
2024-03-05 11:29:17 +01:00
"Afghanistan": "AF",
"Albania": "AL",
"Algeria": "DZ",
"Andorra": "AD",
"Antigua And Barbuda": "AG",
"Argentina": "AR",
"Armenia": "AM",
"Aruba": "AW",
"Australia": "AU",
"Austria": "AT",
"Azerbaijan": "AZ",
"Bahrain": "BH",
"Bangladesh": "BD",
"Belarus": "BY",
"Belgium": "BE",
"Bhutan": "BT",
"Bolivia": "BO",
"Bosnia And Herzegovina": "BA",
"Botswana": "BW",
"Brazil": "BR",
"Bulgaria": "BG",
"Cambodia": "KH",
"Canada": "CA",
"Chile": "CL",
"China": "CN",
"Colombia": "CO",
"Costa Rica": "CR",
"Croatia": "HR",
"Cyprus": "CY",
"Czech Republic": "CZ",
"Denmark": "DK",
"Djibouti": "DJ",
"Dominican Republic": "DO",
"Ecuador": "EC",
"Egypt": "EG",
"El Salvador": "SV",
"Eritrea": "tER",
"Estonia": "EE",
"Ethiopia": "ET",
"Faroe Islands": "FO",
"Finland": "FI",
"France": "FR",
"Georgia": "GE",
"Germany": "DE",
"Greece": "GR",
"Greenland": "GL",
"Guatemala": "GT",
"Haiti": "HT",
"Honduras": "HN",
"Hong Kong": "HK",
"Hungary": "HU",
"Iceland": "IS",
"India": "IN",
"Indonesia": "ID",
"Iran, Islamic Republic Of": "IR",
"Iraq": "IQ",
"Ireland": "IE",
"Israel": "IL",
"Italy": "IT",
"Japan": "JP",
"Jordan": "JO",
"Kazakhstan": "KZ",
"Kenya": "KE",
"Korea, Republic Of": "KR",
"Kuwait": "KW",
"Kyrgyzstan": "KG",
"Latvia": "LV",
"Lebanon": "LB",
"Libyan Arab Jamahiriya": "LY",
"Liechtenstein": "LI",
"Lithuania": "LT",
"Luxembourg": "LU",
"Macedonia": "MK",
"Madagascar": "MG",
"Malaysia": "MY",
"Maldives": "MV",
"Malta": "MT",
"Mexico": "MX",
"Mongolia": "MN",
"Morocco": "MA",
"Myanmar": "MM",
"Nepal": "NP",
"Netherlands": "NL",
"Netherlands Antilles": "pAN",
"New Zealand": "NZ",
"Nicaragua": "NI",
"Nigeria": "NG",
"Norway": "NO",
"Oman": "OM",
"Pakistan": "PK",
"Panama": "PA",
"Paraguay": "PY",
"Peru": "PE",
"Philippines": "PH",
"Poland": "PL",
"Portugal": "PT",
"Puerto Rico": "PR",
"Qatar": "QA",
"Romania": "RO",
"Russian Federation": "RU",
"Rwanda": "RW",
"Saudi Arabia": "SA",
"Senegal": "SN",
"Serbia And Montenegro": "CS",
"Singapore": "SG",
"Slovakia": "SK",
"Slovenia": "SI",
"Somalia": "SO",
"South Africa": "ZA",
"Spain": "ES",
"Sri Lanka": "LK",
"Sudan": "SD",
"Sweden": "SE",
"Switzerland": "CH",
"Syrian Arab Republic": "SY",
"Taiwan": "TW",
"Tajikistan": "TJ",
"Thailand": "TH",
"Tunisia": "TN",
"Turkey": "TR",
"Turkmenistan": "TM",
"Uganda": "UG",
"Ukraine": "UA",
"United Arab Emirates": "AE",
"United Kingdom": "GB",
"United States": "US",
"Uruguay": "UY",
"Uzbekistan": "UZ",
"Venezuela": "VE",
"Viet Nam": "VN",
"Yemen": "YE",
"Zimbabwe": "ZW"
2020-12-09 22:26:29 +01:00
},
error: null,
title: '',
searchItems: [],
offers: {},
2020-12-16 21:11:46 +01:00
seasons: {},
2020-12-09 22:26:29 +01:00
step: 1,
},
methods: {
search() {
2024-03-05 11:29:17 +01:00
fetch(
`${JUSTWATCH_API_DOMAIN}/graphql`,
{
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"operationName": "GetSuggestedTitles",
"variables": {
"country": "FR",
"language": "fr",
"first": 4,
"filter": {"searchQuery": this.title}
},
"query": "query GetSuggestedTitles($country: Country!, $language: Language!, $first: Int!, $filter: TitleFilter) { popularTitles(country: $country, first: $first, filter: $filter) { edges { node { ...SuggestedTitle __typename } __typename } __typename }}fragment SuggestedTitle on MovieOrShow { id objectType objectId content(country: $country, language: $language) { fullPath title originalReleaseYear posterUrl fullPath __typename } watchNowOffer(country: $country, platform: WEB) { id standardWebURL package { id packageId __typename } __typename } offers(country: $country, platform: WEB) { monetizationType presentationType standardWebURL package { id packageId __typename } id __typename } __typename}",
}),
credentials : "include",
}
)
2020-12-09 22:26:29 +01:00
.then(response => response.json())
.then(response => {
this.error = null;
2024-03-05 11:29:17 +01:00
if (!response.data.popularTitles.edges || response.data.popularTitles.length == 0) {
2020-12-09 22:26:29 +01:00
this.error = 'Not found'
return;
}
2024-03-05 11:29:17 +01:00
this.searchItems = response.data.popularTitles.edges.map((item) => {
2020-12-14 20:34:17 +01:00
var poster = null;
2024-03-05 11:29:17 +01:00
if (item.node.content.posterUrl) {
poster = item.node.content.posterUrl.replace('{profile}', 's276');
2020-12-14 20:34:17 +01:00
}
2020-12-09 22:26:29 +01:00
return {
2024-03-05 11:29:17 +01:00
id: item.node.id,
title: item.node.content.title,
type: item.node.objectType,
poster_url: `https://images.justwatch.com${poster}`,
fullPath: item.node.content.fullPath,
2020-12-09 22:26:29 +01:00
};
});
2020-12-16 21:11:46 +01:00
2020-12-09 22:26:29 +01:00
this.step += 1;
})
.catch(exc => this.error = exc);
},
2020-12-12 12:28:54 +01:00
toggleCheckbox(localeId) {
if (this.checkedLocales.indexOf(localeId) !== -1) {
var index = this.checkedLocales.indexOf(localeId);
this.checkedLocales.splice(index, 1);
} else {
this.checkedLocales.push(localeId);
}
2020-12-14 20:52:22 +01:00
localStorage.setItem('checkedLocales', JSON.stringify(this.checkedLocales));
2020-12-12 12:28:54 +01:00
},
2020-12-16 21:11:46 +01:00
preloadItem(index) {
var searchItem = this.searchItems[index];
2024-03-05 11:29:17 +01:00
fetch(
`${JUSTWATCH_API_DOMAIN}/graphql`,
{
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"operationName": "GetUrlTitleDetails",
"variables": {
"platform": "WEB",
"fullPath": searchItem.fullPath,
"language": "fr",
"country": "FR",
"episodeMaxLimit": 20,
"allowSponsoredRecommendations": {
"appId": "3.8.2-webapp#dec565e",
"country": "FR",
"language": "fr",
"pageType": "VIEW_TITLE_DETAIL",
"placement": "DETAIL_PAGE",
"platform": "WEB",
"supportedObjectTypes": ["MOVIE", "SHOW", "GENERIC_TITLE_LIST"],
"supportedFormats": ["IMAGE", "VIDEO"]
2020-12-16 21:11:46 +01:00
}
2024-03-05 11:29:17 +01:00
},
"query": "query GetUrlTitleDetails($fullPath: String!, $country: Country!, $language: Language!, $episodeMaxLimit: Int, $platform: Platform! = WEB, $allowSponsoredRecommendations: SponsoredRecommendationsInput, $format: ImageFormat, $backdropProfile: BackdropProfile) {\n urlV2(fullPath: $fullPath) {\n id\n metaDescription\n metaKeywords\n metaRobots\n metaTitle\n heading1\n heading2\n htmlContent\n node {\n id\n __typename\n ... on MovieOrShowOrSeason {\n plexPlayerOffers: offers(\n country: $country\n platform: $platform\n filter: {packages: [\"pxp\"]}\n ) {\n id\n standardWebURL\n package {\n id\n packageId\n clearName\n technicalName\n shortName\n __typename\n }\n __typename\n }\n disneyOffersCount: offerCount(\n country: $country\n platform: $platform\n filter: {packages: [\"dnp\"]}\n )\n objectType\n objectId\n offerCount(country: $country, platform: $platform)\n offers(country: $country, platform: $platform) {\n monetizationType\n elementCount\n package {\n id\n packageId\n clearName\n __typename\n }\n __typename\n }\n watchNowOffer(country: $country, platform: $platform) {\n id\n standardWebURL\n __typename\n }\n promotedBundles(country: $country, platform: $platform) {\n promotionUrl\n __typename\n }\n availableTo(country: $country, platform: $platform) {\n availableCountDown(country: $country)\n availableToDate\n package {\n id\n shortName\n __typename\n }\n __typename\n }\n fallBackClips: content(country: \"US\", language: \"en\") {\n videobusterClips: clips(providers: [VIDEOBUSTER]) {\n ...TrailerClips\n __typename\n }\n dailymotionClips: clips(providers: [DAILYMOTION]) {\n ...TrailerClips\n __typename\n }\n __typename\n }\n content(country: $country, language: $language) {\n backdrops {\n backdropUrl\n __typename\n }\n fullBackdrops: backdrops(profile: S1920, format: JPG) {\n backdropUrl\n __typename\n }\n clips {\n ...TrailerClips\n __typename\n }\n videobusterClips: clips(providers: [VIDEOBUSTER]) {\n ...TrailerClips\n __typename\n }\n dailymotionClips: clips(providers: [DAILYMOTION]) {\n ...TrailerClips\n __typename\n }\n externalIds {\n imdbId\n __typename\n }\n fullPath\n genres {\n shortName\n __typename\n }\n posterUrl\n fullPosterUrl: posterUrl(profile: S718, format: JPG)\n runtime\n isReleased\n scoring {\n imdbScore\n imdbVotes\n tmdbPopularity\n tmdbScore\n jwRating\n __typename\n }\n shortDescription\n title\n originalReleaseYear\n originalReleaseDate\n upcomingReleases(releaseTypes: DIGITAL) {\n releaseCountDown(country: $country)\n releaseDate\n label\n package {\n id\n packageId\n shortName\n clearName\n __typename\n }\n __typename\n }\n ... on MovieOrShowContent {\n originalTitle\n ageCertification\n credits {\n role\n name\n characterName\n personId\n __t
}),
credentials : "include"
}
)
.then(response => response.json())
.then(response => {
this.seasons = {};
if (response.data.urlV2.node.seasons && response.data.urlV2.node.seasons.length > 0) {
this.seasons = response.data.urlV2.node.seasons.map((item) => {
var poster = null;
if (item.content.posterUrl) {
poster = item.content.posterUrl.replace('{profile}', 's276');
}
return {
id: item.id,
title: item.content.title,
type: item.objectType,
poster_url: `https://images.justwatch.com${poster}`,
fullPath: item.content.fullPath,
};
});
this.step += 1;
} else {
this.step += 1;
this.loadItem(index, false);
}
});
2020-12-16 21:11:46 +01:00
},
loadItem(index, isSeason) {
2020-12-09 22:26:29 +01:00
this.offers = {};
this.error = null;
var promises = [];
2020-12-12 12:28:54 +01:00
this.checkedLocales.forEach((locale) => {
2020-12-09 22:26:29 +01:00
var searchItem = this.searchItems[index];
2020-12-16 21:11:46 +01:00
if (isSeason) {
searchItem = this.seasons[index];
}
2024-03-05 11:29:17 +01:00
promises.push(fetch(
`${JUSTWATCH_API_DOMAIN}/graphql`,
{
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"operationName": "GetUrlTitleDetails",
"variables": {
"platform": "WEB",
"fullPath": searchItem.fullPath,
"language": "fr",
"country": locale,
"episodeMaxLimit": 20,
"allowSponsoredRecommendations": {
"appId": "3.8.2-webapp#dec565e",
"country": "FR",
"language": "fr",
"pageType": "VIEW_TITLE_DETAIL",
"placement": "DETAIL_PAGE",
"platform": "WEB",
"supportedObjectTypes": ["MOVIE", "SHOW", "GENERIC_TITLE_LIST"],
"supportedFormats": ["IMAGE", "VIDEO"]
}
},
"query": "query GetUrlTitleDetails($fullPath: String!, $country: Country!, $language: Language!, $episodeMaxLimit: Int, $platform: Platform! = WEB, $allowSponsoredRecommendations: SponsoredRecommendationsInput, $format: ImageFormat, $backdropProfile: BackdropProfile) {\n urlV2(fullPath: $fullPath) {\n id\n metaDescription\n metaKeywords\n metaRobots\n metaTitle\n heading1\n heading2\n htmlContent\n node {\n id\n __typename\n ... on MovieOrShowOrSeason {\n plexPlayerOffers: offers(\n country: $country\n platform: $platform\n filter: {packages: [\"pxp\"]}\n ) {\n id\n standardWebURL\n package {\n id\n packageId\n clearName\n technicalName\n shortName\n __typename\n }\n __typename\n }\n disneyOffersCount: offerCount(\n country: $country\n platform: $platform\n filter: {packages: [\"dnp\"]}\n )\n objectType\n objectId\n offerCount(country: $country, platform: $platform)\n offers(country: $country, platform: $platform) {\n monetizationType\n elementCount\n package {\n id\n packageId\n clearName\n __typename\n }\n __typename\n }\n watchNowOffer(country: $country, platform: $platform) {\n id\n standardWebURL\n __typename\n }\n promotedBundles(country: $country, platform: $platform) {\n promotionUrl\n __typename\n }\n availableTo(country: $country, platform: $platform) {\n availableCountDown(country: $country)\n availableToDate\n package {\n id\n shortName\n __typename\n }\n __typename\n }\n fallBackClips: content(country: \"US\", language: \"en\") {\n videobusterClips: clips(providers: [VIDEOBUSTER]) {\n ...TrailerClips\n __typename\n }\n dailymotionClips: clips(providers: [DAILYMOTION]) {\n ...TrailerClips\n __typename\n }\n __typename\n }\n content(country: $country, language: $language) {\n backdrops {\n backdropUrl\n __typename\n }\n fullBackdrops: backdrops(profile: S1920, format: JPG) {\n backdropUrl\n __typename\n }\n clips {\n ...TrailerClips\n __typename\n }\n videobusterClips: clips(providers: [VIDEOBUSTER]) {\n ...TrailerClips\n __typename\n }\n dailymotionClips: clips(providers: [DAILYMOTION]) {\n ...TrailerClips\n __typename\n }\n externalIds {\n imdbId\n __typename\n }\n fullPath\n genres {\n shortName\n __typename\n }\n posterUrl\n fullPosterUrl: posterUrl(profile: S718, format: JPG)\n runtime\n isReleased\n scoring {\n imdbScore\n imdbVotes\n tmdbPopularity\n tmdbScore\n jwRating\n __typename\n }\n shortDescription\n title\n originalReleaseYear\n originalReleaseDate\n upcomingReleases(releaseTypes: DIGITAL) {\n releaseCountDown(country: $country)\n releaseDate\n label\n package {\n id\n packageId\n shortName\n clearName\n __typename\n }\n __typename\n }\n ... on MovieOrShowContent {\n originalTitle\n ageCertification\n credits {\n role\n name\n characterName\n personId\n
}),
credentials : "include"
}
)
2020-12-09 22:26:29 +01:00
.then(response => response.json())
.then(response => {
2024-03-05 11:29:17 +01:00
if (!response.data.urlV2.node.offers) {
this.offers[locale] = [];
2020-12-09 22:26:29 +01:00
return;
}
2024-03-05 11:29:17 +01:00
this.offers[locale] = response.data.urlV2.node.offers
.filter(item => item.monetizationType == 'FLATRATE' || item.monetizationType == 'ADS')
.map(item => item.package.clearName);
2020-12-09 22:26:29 +01:00
this.offers[locale] = [...new Set(this.offers[locale])];
})
.catch(exc => this.error = exc)
);
})
Promise.all(promises).then(() => this.step += 1);
},
},
});
</script>
</body>
</html>