-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(justwatch): Leverage trakt to gather justwatch providers
- Loading branch information
Showing
2 changed files
with
73 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,70 @@ | ||
from app.modules.justwatch import JustWatch | ||
from app.modules.trakt import Trakt | ||
|
||
SHOWS = [ | ||
("Loki", 2021), | ||
("Stranger Things", 2016), | ||
("Reacher", 2022), | ||
("Logan", 2017), | ||
("Severance", 2022), | ||
("Cobra Kai", 2018), | ||
("Bo Burnham: What", 2013), | ||
("Interstellar", 2014), | ||
("Eraserhead", 1977), | ||
("Life on Earth", 1979), | ||
("24", 2001), | ||
("Current Sea", 2020), | ||
] | ||
|
||
|
||
def gather_providers(): | ||
# Create a JustWatch instance | ||
justwatch = JustWatch("US", "en") | ||
|
||
def gather_providers(trakt_id, trakt_secret): | ||
# Create a Trakt instance | ||
trakt = Trakt( | ||
trakt_id, | ||
trakt_secret, | ||
) | ||
|
||
# Get the most popular shows | ||
shows = trakt.get_all_items_for_url( | ||
"show", | ||
{ | ||
"max_items_per_list": 200, | ||
"lists": [ | ||
"https://trakt.tv/shows/trending", | ||
"https://trakt.tv/shows/popular", | ||
"https://trakt.tv/shows/watched/yearly", | ||
"https://trakt.tv/shows/collected/yearly", | ||
], | ||
}, | ||
) | ||
|
||
# List of country codes to check providers for | ||
countries = [ | ||
"US", | ||
"BR", | ||
"NG", | ||
"IN", | ||
"CN", | ||
"RU", | ||
"AU", | ||
"PT", | ||
"FR", | ||
"DE", | ||
"ES", | ||
"IT", | ||
"JP", | ||
"KR", | ||
"GB", | ||
] | ||
|
||
# Create a set to store the providers | ||
providers = set() | ||
|
||
# Iterate shows and collect all the different providers in a set | ||
for title, year in SHOWS: | ||
result = justwatch.search_by_title_and_year(title, year, "show") | ||
if result: | ||
for offer in result.offers: | ||
providers.add(offer.package.technical_name) | ||
# Iterate over the countries | ||
for country in countries: | ||
# Create a JustWatch instance for the current country | ||
justwatch = JustWatch(country, "en") | ||
|
||
# Iterate shows and collect all the different providers in a set | ||
for show in shows: | ||
try: | ||
title = shows[show]["trakt"].title | ||
year = shows[show]["trakt"].year | ||
result = justwatch.search_by_title_and_year(title, year, "show") | ||
if result: | ||
for offer in result.offers: | ||
providers.add(offer.package.technical_name) | ||
except AttributeError: | ||
# Skip if the show doesn't have a title or year | ||
continue | ||
except TypeError: | ||
# There is a null error inside justwatch library, this is a workaround | ||
continue | ||
|
||
# Print the providers | ||
print(providers) | ||
return providers |