Switch to tmdb's API Read Access Token

This commit is contained in:
Zoe Roux 2025-05-09 02:18:49 +02:00
parent 819dbf3aab
commit 47f6c66435
No known key found for this signature in database
2 changed files with 27 additions and 17 deletions

View File

@ -1,10 +1,15 @@
# vi: ft=sh # vi: ft=sh
# shellcheck disable=SC2034 # shellcheck disable=SC2034
KYOO_URL="http://api:3567/api"
KYOO_APIKEY=""
# Root directory that will be traversed to find video files (inside the container) # Root directory that will be traversed to find video files (inside the container)
SCANNER_LIBRARY_ROOT="/video" SCANNER_LIBRARY_ROOT="/video"
# A pattern (regex) to ignore video files. # A pattern (regex) to ignore video files.
LIBRARY_IGNORE_PATTERN=".*/[dD]ownloads?/.*" LIBRARY_IGNORE_PATTERN=".*/[dD]ownloads?/.*"
# Keep those empty to use kyoo's default api key. You can also specify a custom API key if you want.
# go to https://www.themoviedb.org/settings/api and copy the read access token (not the api key)
THEMOVIEDB_API_ACCESS_TOKEN=""
KYOO_URL="http://api:3567/api"
KYOO_APIKEY=""

View File

@ -25,20 +25,21 @@ logger = getLogger(__name__)
class TheMovieDatabase(Provider): class TheMovieDatabase(Provider):
DEFAULT_API_KEY = "c9f328a01011b28f22483717395fc3fa" THEMOVIEDB_API_ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjOWYzMjhhMDEwMTFiMjhmMjI0ODM3MTczOTVmYzNmYSIsIm5iZiI6MTU4MTYzMTExOS44NjgsInN1YiI6IjVlNDVjNjhmODNlZTY3MDAxMTFmMmU5NiIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.CeXrQwgB3roCAVs-Z2ayLRx99VIJbym7XSpcRjGzyLA"
def __init__( def __init__(self) -> None:
self,
client: ClientSession,
api_key: str,
) -> None:
super().__init__() super().__init__()
self._client = client self._client = ClientSession(
self._base = "https://api.themoviedb.org/3" base_url="https://api.themoviedb.org/3",
self._image_path = "https://image.tmdb.org/t/p/original" headers={
self._api_key = ( "User-Agent": "kyoo scanner v5",
os.environ.get("THEMOVIEDB_APIKEY") or TheMovieDatabase.DEFAULT_API_KEY "X-API-KEY": (
os.environ.get("THEMOVIEDB_API_ACCESS_TOKEN")
or TheMovieDatabase.THEMOVIEDB_API_ACCESS_TOKEN
),
},
) )
self._image_path = "https://image.tmdb.org/t/p/original"
self._genre_map = { self._genre_map = {
28: Genre.ACTION, 28: Genre.ACTION,
12: Genre.ADVENTURE, 12: Genre.ADVENTURE,
@ -67,6 +68,12 @@ class TheMovieDatabase(Provider):
10768: [Genre.WAR, Genre.POLITICS], 10768: [Genre.WAR, Genre.POLITICS],
} }
async def __aenter__(self):
return self
async def __aexit__(self):
await self._client.close()
@property @property
@override @override
def name(self) -> str: def name(self) -> str:
@ -610,9 +617,7 @@ class TheMovieDatabase(Provider):
not_found_fail: str | None = None, not_found_fail: str | None = None,
): ):
params = {k: v for k, v in params.items() if v is not None} if params else {} params = {k: v for k, v in params.items() if v is not None} if params else {}
async with self._client.get( async with self._client.get(path, params=params) as r:
f"{self._base}/{path}", params={"api_key": self._api_key, **params}
) as r:
if not_found_fail and r.status == 404: if not_found_fail and r.status == 404:
raise ProviderError(not_found_fail) raise ProviderError(not_found_fail)
r.raise_for_status() r.raise_for_status()