memorium/lib/tmdb.ts

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-07-31 17:21:17 +02:00
import * as cache from "@lib/cache/cache.ts";
2023-07-31 04:19:04 +02:00
import { MovieDb } from "https://esm.sh/moviedb-promise@3.4.1";
const moviedb = new MovieDb(Deno.env.get("TMDB_API_KEY") || "");
2023-08-09 23:51:40 +02:00
const CACHE_INTERVAL = 1000 * 60 * 24 * 30;
2023-07-31 04:19:04 +02:00
export const searchMovie = (query: string, year?: number) =>
2023-08-09 23:51:40 +02:00
cache.cacheFunction({
fn: () => moviedb.searchMovie({ query, year }),
id: `query:moviesearch:${query}${year ? `-${year}` : ""}`,
2023-08-09 23:51:40 +02:00
options: {
expires: CACHE_INTERVAL,
},
});
2023-08-07 14:44:04 +02:00
2023-08-09 23:51:40 +02:00
export const searchTVShow = (query: string) =>
cache.cacheFunction(
{
fn: () => moviedb.searchTv({ query }),
id: `query:tvshowsearch:${query}`,
options: {
expires: CACHE_INTERVAL,
},
},
);
2023-07-31 04:19:04 +02:00
2023-08-09 23:51:40 +02:00
export const getMovie = (id: number) =>
cache.cacheFunction({
fn: () => moviedb.movieInfo({ id }),
id: `query:movie:${id}`,
options: {
expires: CACHE_INTERVAL,
},
});
2023-08-08 21:50:23 +02:00
2023-08-09 23:51:40 +02:00
export const getSeries = (id: number) =>
cache.cacheFunction({
fn: () => moviedb.tvInfo({ id }),
id: `query:tvshow:${id}`,
options: {
expires: CACHE_INTERVAL,
},
});
2023-07-31 17:21:17 +02:00
2023-08-09 23:51:40 +02:00
export const getMovieCredits = (id: number) =>
cache.cacheFunction({
fn: () => moviedb.movieCredits(id),
id: `query:moviecredits:${id}`,
options: {
expires: CACHE_INTERVAL,
},
});
export const getSeriesCredits = (id: number) =>
cache.cacheFunction({
fn: () => moviedb.tvCredits(id),
id: `query:tvshowcredits:${id}`,
options: {
expires: CACHE_INTERVAL,
},
});
2023-08-08 21:50:23 +02:00
export async function getMovieGenre(id: number) {
const genres = await cache.get("/genres/movies");
return moviedb.genreTvList();
}
export async function getSeriesGenre(id: number) {
const genres = await cache.get("/genres/series");
}
2023-07-31 17:21:17 +02:00
export async function getMoviePoster(id: string): Promise<ArrayBuffer> {
const posterUrl = `https://image.tmdb.org/t/p/original/${id}`;
const response = await fetch(posterUrl);
const poster = await response.arrayBuffer();
return poster;
}