|
1 | | -GRAPHQL_SEARCH_QUERY = """ |
| 1 | +_GRAPHQL_SEARCH_QUERY = """ |
2 | 2 | query GetSearchTitles( |
3 | 3 | $searchTitlesFilter: TitleFilter!, |
4 | 4 | $country: Country!, |
|
74 | 74 | """ |
75 | 75 |
|
76 | 76 |
|
77 | | -def prepare_search_request(title: str, county: str, lang: str, count: int, best_only: bool) -> dict: |
| 77 | +def prepare_search_request( |
| 78 | + title: str, country: str, language: str, count: int, best_only: bool |
| 79 | +) -> dict: |
78 | 80 | """Prepare search request for JustWatch GraphQL API. |
| 81 | + Country code should be two uppercase characters, |
| 82 | + however lowercase code will be converted to uppercase. |
79 | 83 |
|
80 | 84 | Args: |
81 | 85 | title: title to search |
82 | | - county: country to search for offers |
83 | | - lang: language of responses |
| 86 | + country: country to search for offers |
| 87 | + language: language of responses |
84 | 88 | count: how many responses should be returned |
85 | 89 | best_only: return only best offers if True, return all offers if False |
86 | 90 |
|
87 | 91 | Returns: |
88 | 92 | JSON/dict with GraphQL POST body |
89 | 93 | """ |
| 94 | + assert len(country) == 2, f"Invalid country code: {country}, code must be 2 characters long" |
90 | 95 | return { |
91 | 96 | "operationName": "GetSearchTitles", |
92 | 97 | "variables": { |
93 | 98 | "first": count, |
94 | 99 | "searchTitlesFilter": {"searchQuery": title}, |
95 | | - "language": lang, |
96 | | - "country": county, |
| 100 | + "language": language, |
| 101 | + "country": country.upper(), |
97 | 102 | "format": "JPG", |
98 | 103 | "profile": "S718", |
99 | 104 | "backdropProfile": "S1920", |
100 | 105 | "filter": {"bestOnly": best_only}, |
101 | 106 | }, |
102 | | - "query": GRAPHQL_SEARCH_QUERY, |
| 107 | + "query": _GRAPHQL_SEARCH_QUERY, |
103 | 108 | } |
0 commit comments