Skip to content

Commit

Permalink
Add collection method
Browse files Browse the repository at this point in the history
Signed-off-by: starry69 <starry369126@outlook.com>
  • Loading branch information
starry-shivam committed Sep 11, 2020
1 parent d05bc43 commit 755f795
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pymoviedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .excs import *

__author__ = ["Stɑrry Shivɑm"]
__version__ = 1.6
__version__ = 1.7

if __name__ == "__main__":
from pprint import pprint
Expand Down
38 changes: 38 additions & 0 deletions pymoviedb/pytmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,44 @@ def alternative_titles(

raise TmdbApiError(resp.text)

def collection(self, collection_id: int, language: str = "en") -> Dict[str, Any]:
"""
Get collection details by id.
"""

payload = {"api_key": self.api_key, "language": language}

resp = get(self.base_url + f"/collection/{collection_id}", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def search_collection(
self, query: str, language: str = "en", page: Optional[int] = 1
) -> Dict[str, Any]:
"""
Search for collections.
"""

payload = {
"api_key": self.api_key,
"language": language,
"query": query,
"page": page,
}

resp = get(self.base_url + "/search/collection", params=payload)

if resp.status_code == 200:

check_res = resp.json()["results"]
if len(check_res) <= 0:
raise ZeroResultsFound(resp.text)
return resp.json()

raise TmdbApiError(resp.text)


############################## TvShows class ##############################

Expand Down

0 comments on commit 755f795

Please sign in to comment.