fix themoviedb api

This commit is contained in:
jxxghp
2025-07-31 08:40:24 +08:00
parent 8b708e8939
commit ca51880798
8 changed files with 297 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
import os
from ..tmdb import TMDb
from ..exceptions import TMDbException
from ..tmdb import TMDb
class Account(TMDb):
@@ -35,6 +35,16 @@ class Account(TMDb):
params="session_id=%s" % self.session_id
)
async def async_details(self):
"""
Get your account details.(异步版本)
:return:
"""
return await self._async_request_obj(
self._urls["details"],
params="session_id=%s" % self.session_id
)
def created_lists(self, page=1):
"""
Get all of the lists created by an account. Will include private lists if you are the owner.
@@ -47,6 +57,18 @@ class Account(TMDb):
key="results"
)
async def async_created_lists(self, page=1):
"""
Get all of the lists created by an account. Will include private lists if you are the owner.(异步版本)
:param page: int
:return:
"""
return await self._async_request_obj(
self._urls["created_lists"] % self.account_id,
params="session_id=%s&page=%s" % (self.session_id, page),
key="results"
)
def _get_list(self, url, asc_sort=True, page=1):
params = "session_id=%s&page=%s" % (self.session_id, page)
if asc_sort is False:
@@ -57,6 +79,16 @@ class Account(TMDb):
key="results"
)
async def _async_get_list(self, url, asc_sort=True, page=1):
params = "session_id=%s&page=%s" % (self.session_id, page)
if asc_sort is False:
params += "&sort_by=created_at.desc"
return await self._async_request_obj(
self._urls[url] % self.account_id,
params=params,
key="results"
)
def favorite_movies(self, asc_sort=True, page=1):
"""
Get the list of your favorite movies.
@@ -66,6 +98,15 @@ class Account(TMDb):
"""
return self._get_list("favorite_movies", asc_sort=asc_sort, page=page)
async def async_favorite_movies(self, asc_sort=True, page=1):
"""
Get the list of your favorite movies.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("favorite_movies", asc_sort=asc_sort, page=page)
def favorite_tv_shows(self, asc_sort=True, page=1):
"""
Get the list of your favorite TV shows.
@@ -75,6 +116,15 @@ class Account(TMDb):
"""
return self._get_list("favorite_tv", asc_sort=asc_sort, page=page)
async def async_favorite_tv_shows(self, asc_sort=True, page=1):
"""
Get the list of your favorite TV shows.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("favorite_tv", asc_sort=asc_sort, page=page)
def mark_as_favorite(self, media_id, media_type, favorite=True):
"""
This method allows you to mark a movie or TV show as a favorite item.
@@ -95,6 +145,26 @@ class Account(TMDb):
}
)
async def async_mark_as_favorite(self, media_id, media_type, favorite=True):
"""
This method allows you to mark a movie or TV show as a favorite item.(异步版本)
:param media_id: int
:param media_type: str
:param favorite:bool
"""
if media_type not in ["tv", "movie"]:
raise TMDbException("Media Type should be tv or movie.")
await self._async_request_obj(
self._urls["favorite"] % self.account_id,
params="session_id=%s" % self.session_id,
method="POST",
json={
"media_type": media_type,
"media_id": media_id,
"favorite": favorite,
}
)
def unmark_as_favorite(self, media_id, media_type):
"""
This method allows you to unmark a movie or TV show as a favorite item.
@@ -103,6 +173,14 @@ class Account(TMDb):
"""
self.mark_as_favorite(media_id, media_type, favorite=False)
async def async_unmark_as_favorite(self, media_id, media_type):
"""
This method allows you to unmark a movie or TV show as a favorite item.(异步版本)
:param media_id: int
:param media_type: str
"""
await self.async_mark_as_favorite(media_id, media_type, favorite=False)
def rated_movies(self, asc_sort=True, page=1):
"""
Get a list of all the movies you have rated.
@@ -112,6 +190,15 @@ class Account(TMDb):
"""
return self._get_list("rated_movies", asc_sort=asc_sort, page=page)
async def async_rated_movies(self, asc_sort=True, page=1):
"""
Get a list of all the movies you have rated.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("rated_movies", asc_sort=asc_sort, page=page)
def rated_tv_shows(self, asc_sort=True, page=1):
"""
Get a list of all the TV shows you have rated.
@@ -121,6 +208,15 @@ class Account(TMDb):
"""
return self._get_list("rated_tv", asc_sort=asc_sort, page=page)
async def async_rated_tv_shows(self, asc_sort=True, page=1):
"""
Get a list of all the TV shows you have rated.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("rated_tv", asc_sort=asc_sort, page=page)
def rated_episodes(self, asc_sort=True, page=1):
"""
Get a list of all the TV episodes you have rated.
@@ -130,6 +226,15 @@ class Account(TMDb):
"""
return self._get_list("rated_episodes", asc_sort=asc_sort, page=page)
async def async_rated_episodes(self, asc_sort=True, page=1):
"""
Get a list of all the TV episodes you have rated.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("rated_episodes", asc_sort=asc_sort, page=page)
def movie_watchlist(self, asc_sort=True, page=1):
"""
Get a list of all the movies you have added to your watchlist.
@@ -139,6 +244,15 @@ class Account(TMDb):
"""
return self._get_list("movie_watchlist", asc_sort=asc_sort, page=page)
async def async_movie_watchlist(self, asc_sort=True, page=1):
"""
Get a list of all the movies you have added to your watchlist.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("movie_watchlist", asc_sort=asc_sort, page=page)
def tv_show_watchlist(self, asc_sort=True, page=1):
"""
Get a list of all the TV shows you have added to your watchlist.
@@ -148,6 +262,15 @@ class Account(TMDb):
"""
return self._get_list("tv_watchlist", asc_sort=asc_sort, page=page)
async def async_tv_show_watchlist(self, asc_sort=True, page=1):
"""
Get a list of all the TV shows you have added to your watchlist.(异步版本)
:param asc_sort: bool
:param page: int
:return:
"""
return await self._async_get_list("tv_watchlist", asc_sort=asc_sort, page=page)
def add_to_watchlist(self, media_id, media_type, watchlist=True):
"""
Add a movie or TV show to your watchlist.
@@ -168,6 +291,26 @@ class Account(TMDb):
}
)
async def async_add_to_watchlist(self, media_id, media_type, watchlist=True):
"""
Add a movie or TV show to your watchlist.(异步版本)
:param media_id: int
:param media_type: str
:param watchlist: bool
"""
if media_type not in ["tv", "movie"]:
raise TMDbException("Media Type should be tv or movie.")
await self._async_request_obj(
self._urls["watchlist"] % self.account_id,
"session_id=%s" % self.session_id,
method="POST",
json={
"media_type": media_type,
"media_id": media_id,
"watchlist": watchlist,
}
)
def remove_from_watchlist(self, media_id, media_type):
"""
Remove a movie or TV show from your watchlist.
@@ -175,3 +318,11 @@ class Account(TMDb):
:param media_type: str
"""
self.add_to_watchlist(media_id, media_type, watchlist=False)
async def async_remove_from_watchlist(self, media_id, media_type):
"""
Remove a movie or TV show from your watchlist.(异步版本)
:param media_id: int
:param media_type: str
"""
await self.async_add_to_watchlist(media_id, media_type, watchlist=False)

View File

@@ -14,9 +14,23 @@ class Certification(TMDb):
"""
return self._request_obj(self._urls["movie_list"], key="certifications")
async def async_movie_list(self):
"""
Get an up to date list of the officially supported movie certifications on TMDB.(异步版本)
:return:
"""
return await self._async_request_obj(self._urls["movie_list"], key="certifications")
def tv_list(self):
"""
Get an up to date list of the officially supported TV show certifications on TMDB.
:return:
"""
return self._request_obj(self._urls["tv_list"], key="certifications")
async def async_tv_list(self):
"""
Get an up to date list of the officially supported TV show certifications on TMDB.(异步版本)
:return:
"""
return await self._async_request_obj(self._urls["tv_list"], key="certifications")

View File

@@ -20,6 +20,18 @@ class Change(TMDb):
key="results"
)
async def _async_change_list(self, change_type, start_date="", end_date="", page=1):
params = "page=%s" % page
if start_date:
params += "&start_date=%s" % start_date
if end_date:
params += "&end_date=%s" % end_date
return await self._async_request_obj(
self._urls[change_type],
params=params,
key="results"
)
def movie_change_list(self, start_date="", end_date="", page=1):
"""
Get the changes for a movie. By default only the last 24 hours are returned.
@@ -31,6 +43,17 @@ class Change(TMDb):
"""
return self._change_list("movie", start_date=start_date, end_date=end_date, page=page)
async def async_movie_change_list(self, start_date="", end_date="", page=1):
"""
Get the changes for a movie. By default only the last 24 hours are returned.(异步版本)
You can query up to 14 days in a single query by using the start_date and end_date query parameters.
:param start_date: str
:param end_date: str
:param page: int
:return:
"""
return await self._async_change_list("movie", start_date=start_date, end_date=end_date, page=page)
def tv_change_list(self, start_date="", end_date="", page=1):
"""
Get a list of all of the TV show ids that have been changed in the past 24 hours.
@@ -42,6 +65,17 @@ class Change(TMDb):
"""
return self._change_list("tv", start_date=start_date, end_date=end_date, page=page)
async def async_tv_change_list(self, start_date="", end_date="", page=1):
"""
Get a list of all of the TV show ids that have been changed in the past 24 hours.(异步版本)
You can query up to 14 days in a single query by using the start_date and end_date query parameters.
:param start_date: str
:param end_date: str
:param page: int
:return:
"""
return await self._async_change_list("tv", start_date=start_date, end_date=end_date, page=page)
def person_change_list(self, start_date="", end_date="", page=1):
"""
Get a list of all of the person ids that have been changed in the past 24 hours.
@@ -52,3 +86,14 @@ class Change(TMDb):
:return:
"""
return self._change_list("person", start_date=start_date, end_date=end_date, page=page)
async def async_person_change_list(self, start_date="", end_date="", page=1):
"""
Get a list of all of the person ids that have been changed in the past 24 hours.(异步版本)
You can query up to 14 days in a single query by using the start_date and end_date query parameters.
:param start_date: str
:param end_date: str
:param page: int
:return:
"""
return await self._async_change_list("person", start_date=start_date, end_date=end_date, page=page)

View File

@@ -13,3 +13,11 @@ class Credit(TMDb):
:return:
"""
return self._request_obj(self._urls["details"] % credit_id)
async def async_details(self, credit_id):
"""
Get a movie or TV credit details by id.(异步版本)
:param credit_id: int
:return:
"""
return await self._async_request_obj(self._urls["details"] % credit_id)

View File

@@ -13,3 +13,11 @@ class Group(TMDb):
:return:
"""
return self._request_obj(self._urls["details"] % group_id, key="groups")
async def async_details(self, group_id):
"""
Get the details of a TV episode group.(异步版本)
:param group_id: int
:return:
"""
return await self._async_request_obj(self._urls["details"] % group_id, key="groups")

View File

@@ -16,6 +16,14 @@ class Network(TMDb):
"""
return self._request_obj(self._urls["details"] % network_id)
async def async_details(self, network_id):
"""
Get a networks details by id.(异步版本)
:param network_id: int
:return:
"""
return await self._async_request_obj(self._urls["details"] % network_id)
def alternative_names(self, network_id):
"""
Get the alternative names of a network.
@@ -27,6 +35,17 @@ class Network(TMDb):
key="results"
)
async def async_alternative_names(self, network_id):
"""
Get the alternative names of a network.(异步版本)
:param network_id: int
:return:
"""
return await self._async_request_obj(
self._urls["alternative_names"] % network_id,
key="results"
)
def images(self, network_id):
"""
Get the TV network logos by id.
@@ -37,3 +56,14 @@ class Network(TMDb):
self._urls["images"] % network_id,
key="logos"
)
async def async_images(self, network_id):
"""
Get the TV network logos by id.(异步版本)
:param network_id: int
:return:
"""
return await self._async_request_obj(
self._urls["images"] % network_id,
key="logos"
)

View File

@@ -18,6 +18,16 @@ class Provider(TMDb):
key="results"
)
async def async_available_regions(self):
"""
Returns a list of all of the countries we have watch provider (OTT/streaming) data for.(异步版本)
:return:
"""
return await self._async_request_obj(
self._urls["regions"],
key="results"
)
def movie_providers(self, region=None):
"""
Returns a list of the watch provider (OTT/streaming) data we have available for movies.
@@ -29,6 +39,17 @@ class Provider(TMDb):
key="results"
)
async def async_movie_providers(self, region=None):
"""
Returns a list of the watch provider (OTT/streaming) data we have available for movies.(异步版本)
:return:
"""
return await self._async_request_obj(
self._urls["movie"],
params="watch_region=%s" % region if region else "",
key="results"
)
def tv_providers(self, region=None):
"""
Returns a list of the watch provider (OTT/streaming) data we have available for TV series.
@@ -39,3 +60,14 @@ class Provider(TMDb):
params="watch_region=%s" % region if region else "",
key="results"
)
async def async_tv_providers(self, region=None):
"""
Returns a list of the watch provider (OTT/streaming) data we have available for TV series.(异步版本)
:return:
"""
return await self._async_request_obj(
self._urls["tv"],
params="watch_region=%s" % region if region else "",
key="results"
)

View File

@@ -13,3 +13,11 @@ class Review(TMDb):
:return:
"""
return self._request_obj(self._urls["details"] % review_id)
async def async_details(self, review_id):
"""
Get the primary person details by id.(异步版本)
:param review_id: int
:return:
"""
return await self._async_request_obj(self._urls["details"] % review_id)