mirror of
https://github.com/NohamR/JustJustWatch.git
synced 2026-11-25 15:19:49 +00:00
search query function
This commit is contained in:
1 parent
b2b73f6c13
commit
a8a9f25499
3 files changed
+2107
-7
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
https://nobraincellsleft.github.io/JustWatch-Search/title/ts35573
|
||||||
@@ -4,6 +4,7 @@ from pprint import pprint
|
|||||||
import json
|
import json
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
from simple_term_menu import TerminalMenu
|
||||||
|
|
||||||
def country_code_to_flag(code):
|
def country_code_to_flag(code):
|
||||||
return chr(127462 + ord(code[0]) - ord('A')) + chr(127462 + ord(code[1]) - ord('A'))
|
return chr(127462 + ord(code[0]) - ord('A')) + chr(127462 + ord(code[1]) - ord('A'))
|
||||||
@@ -19,7 +20,7 @@ def format_countries(country_codes):
|
|||||||
return ', '.join([f"{country_code_to_flag(code)} {code}" for code in selected_countries]) + f" + {len(country_codes) - len(selected_countries)} more"
|
return ', '.join([f"{country_code_to_flag(code)} {code}" for code in selected_countries]) + f" + {len(country_codes) - len(selected_countries)} more"
|
||||||
else:
|
else:
|
||||||
return ', '.join([f"{country_code_to_flag(code)} {code}" for code in selected_countries])
|
return ', '.join([f"{country_code_to_flag(code)} {code}" for code in selected_countries])
|
||||||
|
|
||||||
def update_url_query(url):
|
def update_url_query(url):
|
||||||
parsed_url = urlparse(url)
|
parsed_url = urlparse(url)
|
||||||
query_params = parse_qs(parsed_url.query)
|
query_params = parse_qs(parsed_url.query)
|
||||||
@@ -38,6 +39,44 @@ def update_url_query(url):
|
|||||||
))
|
))
|
||||||
return new_url
|
return new_url
|
||||||
|
|
||||||
|
def search(query):
|
||||||
|
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',}
|
||||||
|
json_data = {
|
||||||
|
"operationName": "GetSuggestedTitles",
|
||||||
|
"variables": {
|
||||||
|
"country": "US",
|
||||||
|
"language": "en",
|
||||||
|
"first": 5,
|
||||||
|
"filter": {
|
||||||
|
"searchQuery": query,
|
||||||
|
"includeTitlesWithoutUrl": True,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"query": "query GetSuggestedTitles($country: Country!, $language: Language!, $first: Int!, $filter: TitleFilter) {\n popularTitles(country: $country, first: $first, filter: $filter) {\n edges {\n node {\n ...SuggestedTitle\n __typename\n }\n __typename\n }\n __typename\n }\n}\n\nfragment SuggestedTitle on MovieOrShow {\n __typename\n id\n objectType\n objectId\n content(country: $country, language: $language) {\n fullPath\n title\n originalReleaseYear\n posterUrl\n fullPath\n __typename\n }\n watchNowOffer(country: $country, platform: WEB) {\n id\n standardWebURL\n package {\n id\n packageId\n __typename\n }\n __typename\n }\n offers(country: $country, platform: WEB) {\n monetizationType\n presentationType\n standardWebURL\n package {\n id\n packageId\n __typename\n }\n id\n __typename\n }\n}\n",
|
||||||
|
}
|
||||||
|
response = requests.post('https://apis.justwatch.com/graphql', headers=headers, json=json_data).json()
|
||||||
|
options = []
|
||||||
|
for title in response['data']['popularTitles']['edges']:
|
||||||
|
title = title['node']
|
||||||
|
contentTitle = title['content']['title']
|
||||||
|
contentPath = title['content']['fullPath']
|
||||||
|
objectType = title['objectType']
|
||||||
|
originalReleaseYear = title['content']['originalReleaseYear']
|
||||||
|
slug = f"{contentTitle} ({objectType}) - {originalReleaseYear}"
|
||||||
|
if contentPath == '':
|
||||||
|
slug += ' - Unavailable ' + chr(0x1F6A7)
|
||||||
|
options.append({'title': contentTitle, 'path': contentPath, 'objectType': objectType, 'originalReleaseYear': originalReleaseYear, 'slug': slug})
|
||||||
|
options_slug = [option['slug'] for option in options]
|
||||||
|
terminal_menu = TerminalMenu(options_slug)
|
||||||
|
nameselected = options[terminal_menu.show()]
|
||||||
|
if nameselected['path'] == '':
|
||||||
|
print('This title is unavailable')
|
||||||
|
else:
|
||||||
|
print(f"Selected: {nameselected['slug']} - {'https://www.justwatch.com' + nameselected['path']}")
|
||||||
|
path = nameselected['path']
|
||||||
|
fetchdata(path)
|
||||||
|
|
||||||
|
|
||||||
def fetchdata(path):
|
def fetchdata(path):
|
||||||
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',}
|
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',}
|
||||||
countries = [country['iso_3166_2'] for country in requests.get('https://apis.justwatch.com/content/locales/state', headers=headers).json()]
|
countries = [country['iso_3166_2'] for country in requests.get('https://apis.justwatch.com/content/locales/state', headers=headers).json()]
|
||||||
@@ -57,7 +96,7 @@ def fetchdata(path):
|
|||||||
'query': 'query GetUrlTitleDetails($fullPath: String!, $country: Country!, $language: Language!, $episodeMaxLimit: Int, $platform: Platform! = WEB, $allowSponsoredRecommendations: SponsoredRecommendationsInput, $format: ImageFormat, $backdropProfile: BackdropProfile, $streamingChartsFilter: StreamingChartsFilter) {\n urlV2(fullPath: $fullPath) {\n id\n metaDescription\n metaKeywords\n metaRobots\n metaTitle\n heading1\n heading2\n htmlContent\n node {\n ...TitleDetails\n __typename\n }\n __typename\n }\n}\n\nfragment TitleDetails on 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 maxOfferUpdatedAt(country: $country, platform: WEB)\n appleOffers: offers(\n country: $country\n platform: $platform\n filter: {packages: ["atp", "itu"]}\n ) {\n ...TitleOffer\n __typename\n }\n disneyOffersCount: offerCount(\n country: $country\n platform: $platform\n filter: {packages: ["dnp"]}\n )\n starOffersCount: offerCount(\n country: $country\n platform: $platform\n filter: {packages: ["srp"]}\n )\n objectType\n objectId\n offerCount(country: $country, platform: $platform)\n uniqueOfferCount: offerCount(\n country: $country\n platform: $platform\n filter: {bestOnly: true}\n )\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: $country, language: "en") {\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 __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 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 tomatoMeter\n certifiedFresh\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 icon(profile: S100)\n hasRectangularIcon(country: $country, platform: WEB)\n __typename\n }\n __typename\n }\n genres {\n shortName\n translation(language: $language)\n __typename\n }\n subgenres {\n content(country: $country, language: $language) {\n shortName\n name\n __typename\n }\n __typename\n }\n ... on MovieOrShowOrSeasonContent {\n subgenres {\n content(country: $country, language: $language) {\n url: moviesUrl {\n fullPath\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n ... on MovieOrShowContent {\n originalTitle\n ageCertification\n credits {\n role\n name\n characterName\n personId\n __typename\n }\n interactions {\n dislikelistAdditions\n Line truncated
|
'query': 'query GetUrlTitleDetails($fullPath: String!, $country: Country!, $language: Language!, $episodeMaxLimit: Int, $platform: Platform! = WEB, $allowSponsoredRecommendations: SponsoredRecommendationsInput, $format: ImageFormat, $backdropProfile: BackdropProfile, $streamingChartsFilter: StreamingChartsFilter) {\n urlV2(fullPath: $fullPath) {\n id\n metaDescription\n metaKeywords\n metaRobots\n metaTitle\n heading1\n heading2\n htmlContent\n node {\n ...TitleDetails\n __typename\n }\n __typename\n }\n}\n\nfragment TitleDetails on 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 maxOfferUpdatedAt(country: $country, platform: WEB)\n appleOffers: offers(\n country: $country\n platform: $platform\n filter: {packages: ["atp", "itu"]}\n ) {\n ...TitleOffer\n __typename\n }\n disneyOffersCount: offerCount(\n country: $country\n platform: $platform\n filter: {packages: ["dnp"]}\n )\n starOffersCount: offerCount(\n country: $country\n platform: $platform\n filter: {packages: ["srp"]}\n )\n objectType\n objectId\n offerCount(country: $country, platform: $platform)\n uniqueOfferCount: offerCount(\n country: $country\n platform: $platform\n filter: {bestOnly: true}\n )\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: $country, language: "en") {\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 __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 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 tomatoMeter\n certifiedFresh\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 icon(profile: S100)\n hasRectangularIcon(country: $country, platform: WEB)\n __typename\n }\n __typename\n }\n genres {\n shortName\n translation(language: $language)\n __typename\n }\n subgenres {\n content(country: $country, language: $language) {\n shortName\n name\n __typename\n }\n __typename\n }\n ... on MovieOrShowOrSeasonContent {\n subgenres {\n content(country: $country, language: $language) {\n url: moviesUrl {\n fullPath\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n ... on MovieOrShowContent {\n originalTitle\n ageCertification\n credits {\n role\n name\n characterName\n personId\n __typename\n }\n interactions {\n dislikelistAdditions\n Line truncated
|
||||||
}
|
}
|
||||||
response = requests.post('https://apis.justwatch.com/graphql', headers=headers, json=json_data).json()
|
response = requests.post('https://apis.justwatch.com/graphql', headers=headers, json=json_data).json()
|
||||||
last_updated = response['data']['urlV2']['node']['maxOfferUpdatedAt']
|
# last_updated = response['data']['urlV2']['node']['maxOfferUpdatedAt']
|
||||||
# print('last_updated: ', last_updated)
|
# print('last_updated: ', last_updated)
|
||||||
for offer in response['data']['urlV2']['node']['plexPlayerOffers']:
|
for offer in response['data']['urlV2']['node']['plexPlayerOffers']:
|
||||||
service = offer['package']['clearName']
|
service = offer['package']['clearName']
|
||||||
@@ -80,9 +119,12 @@ def fetchdata(path):
|
|||||||
print(tabulate(table_data, headers, tablefmt="grid"))
|
print(tabulate(table_data, headers, tablefmt="grid"))
|
||||||
return SERVICES
|
return SERVICES
|
||||||
|
|
||||||
# url = 'https://www.justwatch.com/fr/serie/mad-dogs'
|
# url = 'https://www.justwatch.com/fr/serie/mad-dogs' # /fr/serie/mad-dogs
|
||||||
url = input('Enter the URL: ')
|
# url = input('Enter the URL: ')
|
||||||
path = url.replace('https://www.justwatch.com', '')
|
# path = url.replace('https://www.justwatch.com', '')
|
||||||
services = fetchdata(path)
|
# services = fetchdata(path)
|
||||||
# with open('services.json', 'w') as f:
|
# with open('services.json', 'w') as f:
|
||||||
# json.dump(services, f, indent=4)
|
# json.dump(services, f, indent=4)
|
||||||
|
|
||||||
|
query = input('Enter the query: ')
|
||||||
|
search(query)
|
||||||
+2057
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user