def tvdb_series_id_episodes_query( token: str, id_tvdb: Union[str, int], episode: Optional[int] = None, season: Optional[int] = None, page: int = 1, language: Optional[Language] = None, cache: bool = True, ) -> dict: """ Allows the user to query against episodes for the given series. Note: Paginated with 100 results per page; omitted imdbId-- when would you ever need to query against both tvdb and imdb series ids? Online docs: api.thetvdb.com/swagger#!/Series/get_series_id_episodes_query. """ Language.ensure_valid_for_tvdb(language) url = f"https://api.thetvdb.com/series/{id_tvdb}/episodes/query" headers = {"Authorization": f"Bearer {token}"} if language: headers["Accept-Language"] = language.a2 parameters = {"airedSeason": season, "airedEpisode": episode, "page": page} status, content = request_json( url, parameters, headers=headers, cache=cache is True and language is None, ) if status == 401: raise MnamerException("invalid token") elif status == 404: raise MnamerNotFoundException elif status != 200 or not content.get("data"): # pragma: no cover raise MnamerNetworkException("TVDb down or unavailable?") return content
def tvdb_series_id( token: str, id_tvdb: Union[str, int], language: Optional[Language] = None, cache: bool = True, ) -> dict: """ Returns a series records that contains all information known about a particular series id. Online docs: api.thetvdb.com/swagger#!/Series/get_series_id. """ Language.ensure_valid_for_tvdb(language) url = f"https://api.thetvdb.com/series/{id_tvdb}" headers = {"Authorization": f"Bearer {token}"} if language: headers["Accept-Language"] = language.a2 status, content = request_json( url, headers=headers, cache=cache is True and language is None ) if status == 401: raise MnamerException("invalid token") elif status == 404: raise MnamerNotFoundException elif status != 200 or not content.get("data"): # pragma: no cover raise MnamerNetworkException("TVDb down or unavailable?") elif content["data"]["id"] == 0: raise MnamerNotFoundException return content
def tvdb_series_id_episodes( token: str, id_tvdb: Union[str, int], page: int = 1, language: Optional[Language] = None, cache: bool = True, ) -> dict: """ All episodes for a given series. Note: Paginated with 100 results per page. Online docs: api.thetvdb.com/swagger#!/Series/get_series_id_episodes. """ Language.ensure_valid_for_tvdb(language) url = f"https://api.thetvdb.com/series/{id_tvdb}/episodes" headers = {"Authorization": f"Bearer {token}"} if language: headers["Accept-Language"] = language.a2 parameters = {"page": page} status, content = request_json( url, parameters, headers=headers, cache=cache is True and language is None, ) if status == 401: raise MnamerException("invalid token") elif status == 404: raise MnamerNotFoundException elif status != 200 or not content.get("data"): # pragma: no cover raise MnamerNetworkException("TVDb down or unavailable?") return content
def tvdb_search_series( token: str, series: Optional[str] = None, id_imdb: Optional[str] = None, id_zap2it: Optional[str] = None, language: Optional[Language] = None, cache: bool = True, ) -> dict: """ Allows the user to search for a series based on the following parameters. Online docs: https://api.thetvdb.com/swagger#!/Search/get_search_series Note: results a maximum of 100 entries per page, no option for pagination. """ Language.ensure_valid_for_tvdb(language) url = "https://api.thetvdb.com/search/series" parameters = {"name": series, "imdbId": id_imdb, "zap2itId": id_zap2it} headers = {"Authorization": f"Bearer {token}"} if language: headers["Accept-Language"] = language.a2 status, content = request_json( url, parameters, headers=headers, cache=cache is True and language is None ) if status == 401: raise MnamerException("invalid token") elif status == 405: raise MnamerException( "series, id_imdb, id_zap2it parameters are mutually exclusive" ) elif status == 404: raise MnamerNotFoundException elif status != 200 or not content.get("data"): # pragma: no cover raise MnamerNetworkException("TVDb down or unavailable?") return content