import Application from "@server/Application"; import TheMovieDb from "@lib/tmdb"; import { env, secret } from "@server/util"; import { readFile } from "fs/promises"; import TVDB from "tvdb-v4"; import Service from "./Service"; import TvDb from "./TvDb"; export default class MovieSearch extends Service { protected tmdb!: TheMovieDb; /** * The instance of TVDB */ protected tvdb!: TvDb; public constructor(app: Application) { super("Movie Search", app); } /** * Start the service */ public start() { this.tvdb = this.app.service("TVDB"); } /** * Boot the service */ public async boot() { let apiKey = await secret(env("TMDB_KEY_FILE")); this.tmdb = new TheMovieDb(apiKey); } /** * Shutdown the service */ public async shutdown() { // no-op } // Interface ----------------------------------------------------------------------------------- /** * Get the details of a movie */ public async details(id: number) { return await this.tmdb.movie(id); } /** * Search for a movie */ public async search(query: string, year?: number) { return await this.tmdb.searchMovie(query, year); // let results = await this.tvdb.searchMovie(query, year); // return results.map(movie => { // image : movie.image_url ? `/api/tvdb/artwork${new URL(movie.image_url).pathname}`: null, // name : movie.name, // year : movie.year // }); } }