Initial commit

This commit is contained in:
√(noham)² committed 2024-09-15 13:53:03 +02:00
commit b2b73f6c13
8 files changed
+247

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
+129
View File
@@ -0,0 +1,129 @@
# Editors
.vscode/
.idea/
# Vagrant
.vagrant/
# Mac/OSX
.DS_Store
# Windows
Thumbs.db
# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
dist_chrome/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# node
node_modules/
+24
View File
@@ -0,0 +1,24 @@
# JustJustWatch
This project pulls data from [JustWatch](https://www.justwatch.com/) and shows details about movies and series.
## Installation
```bash
pip install -r requirements.txt
```
## Usage
```bash
python info.py
```
## Example Usage
### 1. Series Example: Mad Dogs
URL: https://www.justwatch.com/fr/serie/mad-dogs
![readme/result.png](readme/result.png)
### 2. Movie Example: Dune (2020)
URL: https://www.justwatch.com/fr/film/dune-2020
![readme/result2.png](readme/result2.png)
+88
View File
@@ -0,0 +1,88 @@
import requests
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
from pprint import pprint
import json
from tqdm import tqdm
from tabulate import tabulate
def country_code_to_flag(code):
return chr(127462 + ord(code[0]) - ord('A')) + chr(127462 + ord(code[1]) - ord('A'))
def format_countries(country_codes):
representative_flags = ["FR", "GB", "US", "DE"]
selected_countries = [code for code in country_codes if code in representative_flags]
if len(selected_countries) < len(representative_flags):
selected_countries += [code for code in country_codes if code not in selected_countries][:4-len(selected_countries)]
if len(country_codes) > len(selected_countries):
return ', '.join([f"{country_code_to_flag(code)} {code}" for code in selected_countries]) + f" + {len(country_codes) - len(selected_countries)} more"
else:
return ', '.join([f"{country_code_to_flag(code)} {code}" for code in selected_countries])
def update_url_query(url):
parsed_url = urlparse(url)
query_params = parse_qs(parsed_url.query)
keys_to_remove = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
for key in keys_to_remove:
query_params.pop(key, None)
query_params.update(query_params)
new_query_string = urlencode(query_params, doseq=True)
new_url = urlunparse((
parsed_url.scheme,
parsed_url.netloc,
parsed_url.path,
parsed_url.params,
new_query_string,
parsed_url.fragment
))
return new_url
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',}
countries = [country['iso_3166_2'] for country in requests.get('https://apis.justwatch.com/content/locales/state', headers=headers).json()]
print(f"Got {len(countries)} countries")
SERVICES = {}
IDS = []
for country in tqdm(countries):
json_data = {
'operationName': 'GetUrlTitleDetails',
'variables': {
'platform': 'WEB',
'fullPath': path,
'language': 'fr',
'country': country,
'episodeMaxLimit': 100,
},
'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()
last_updated = response['data']['urlV2']['node']['maxOfferUpdatedAt']
# print('last_updated: ', last_updated)
for offer in response['data']['urlV2']['node']['plexPlayerOffers']:
service = offer['package']['clearName']
url = update_url_query(offer['standardWebURL'])
id = offer['package']['id']
if id not in IDS:
IDS.append(id)
infos = {'id': id,'service': service,'url': url,'countries': [country],}
SERVICES[service] = infos
else:
if country not in SERVICES[service]['countries']:
SERVICES[service]['countries'].append(country)
table_data = []
for service, details in SERVICES.items():
formatted_countries = format_countries(details["countries"])
table_data.append([details["service"], formatted_countries, details["url"]])
headers = ["Service", "Countries", "URL"]
print(tabulate(table_data, headers, tablefmt="grid"))
return SERVICES
# url = 'https://www.justwatch.com/fr/serie/mad-dogs'
url = input('Enter the URL: ')
path = url.replace('https://www.justwatch.com', '')
services = fetchdata(path)
# with open('services.json', 'w') as f:
# json.dump(services, f, indent=4)
+1
View File
@@ -0,0 +1 @@
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 likelistAdditLine truncated
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 KiB

+3
View File
@@ -0,0 +1,3 @@
Requests==2.32.3
tabulate==0.9.0
tqdm==4.65.0