@@ -44,6 +44,9 @@ def prepare_search_request(
4444 best_only : bool ,
4545 offset : int ,
4646 providers : list [str ] | str | None ,
47+ min_year : int | None ,
48+ max_year : int | None ,
49+ object_types : list [str ] | str | None ,
4750) -> dict [str , Any ]:
4851 """
4952 Prepare search request for JustWatch GraphQL API.
@@ -66,6 +69,10 @@ def prepare_search_request(
6669 offset (int): Search results offset.
6770 providers (list[str] | str | None): 3-letter service identifier(s),
6871 or `None` for all providers.
72+ min_year (int | None): Minimum release year of returned titles.
73+ max_year (int | None): Maximum release year of returned titles.
74+ object_types (list[str] | str | None): Types of objects to filter for, it seems
75+ that only "SHOW" and "MOVIE" make sense.
6976
7077 Returns:
7178 (dict[str, Any]): JSON with GraphQL POST body.
@@ -75,7 +82,11 @@ def prepare_search_request(
7582 "operationName" : "GetSearchTitles" ,
7683 "variables" : {
7784 "first" : count ,
78- "searchTitlesFilter" : {"searchQuery" : title , "packages" : providers },
85+ "searchTitlesFilter" : {
86+ "searchQuery" : title ,
87+ "packages" : providers ,
88+ ** _list_variables (min_year , max_year , object_types ),
89+ },
7990 ** _common_variables (best_only ),
8091 ** _locale_variables (country , language ),
8192 "offset" : offset or None ,
@@ -118,6 +129,9 @@ def prepare_popular_request(
118129 best_only : bool ,
119130 offset : int ,
120131 providers : list [str ] | str | None ,
132+ min_year : int | None ,
133+ max_year : int | None ,
134+ object_types : list [str ] | str | None ,
121135) -> dict [str , Any ]:
122136 """
123137 Prepare "get popular" request for JustWatch GraphQL API.
@@ -139,6 +153,10 @@ def prepare_popular_request(
139153 offset (int): Search results offset.
140154 providers (list[str] | str | None): 3-letter service identifier(s),
141155 or `None` for all providers.
156+ min_year (int | None): Minimum release year of returned titles.
157+ max_year (int | None): Maximum release year of returned titles.
158+ object_types (list[str] | str | None): Types of objects to filter for, it seems
159+ that only "SHOW" and "MOVIE" make sense.
142160
143161 Returns:
144162 (dict[str, Any]): JSON with GraphQL POST body.
@@ -148,7 +166,10 @@ def prepare_popular_request(
148166 "operationName" : "GetPopularTitles" ,
149167 "variables" : {
150168 "first" : count ,
151- "popularTitlesFilter" : {"packages" : providers },
169+ "popularTitlesFilter" : {
170+ "packages" : providers ,
171+ ** _list_variables (min_year , max_year , object_types ),
172+ },
152173 ** _common_variables (best_only ),
153174 ** _locale_variables (country , language ),
154175 "offset" : offset or None ,
@@ -507,6 +528,16 @@ def _locale_variables(country: str, language: str) -> dict[str, str]:
507528 return {"country" : country .upper (), "language" : language }
508529
509530
531+ def _list_variables (
532+ min_year : int | None , max_year : int | None , object_types : list [str ] | str | None
533+ ) -> dict [str , Any ]:
534+ """Return dict with variables related to looking up lists of titles."""
535+ return {
536+ "objectTypes" : object_types ,
537+ "releaseYear" : {"min" : min_year , "max" : max_year },
538+ }
539+
540+
510541def _raise_for_errors_in_response (json : dict [str , Any ]) -> None :
511542 """Raise JustWatchApiError if given JSON contains `errors` key."""
512543 if "errors" in json :
0 commit comments