diff --git a/src/main.ts b/src/main.ts index fbc049a..f641304 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,10 +44,10 @@ function buildVideoInfo( async function fetchMovieInfo( imdbID: string, + apiKey: string, ): Promise { - const omdbAPIKey = Deno.env.get("OMDB_API_KEY"); const response = await fetch( - `https://www.omdbapi.com/?i=${imdbID}&apikey=${omdbAPIKey}`, + `https://www.omdbapi.com/?i=${imdbID}&apikey=${apiKey}`, ); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); @@ -84,6 +84,14 @@ async function main() { console.log("Usage: deno run main.ts -i "); Deno.exit(1); } + if (!args.k) { + const confirm = prompt( + "No key entered. Are you sure you want to continue? (y/N)", + ); + if (confirm !== "y") { + Deno.exit(1); + } + } // Check if file exists const videoFile: string = String(args.i); if (!await exists(videoFile)) { @@ -93,17 +101,22 @@ async function main() { // Analyze video const videoInfo = analyzeVideo(videoFile); videoInfo.format.filename = resolve(videoFile); - //const imdbID = "tt0108333"; - const imdbID = prompt("Enter IMDb ID. Leave empty to skip"); - let jsonVideoInfo; - if (imdbID) { - const movieInfo = await fetchMovieInfo(imdbID); - jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo); + if (args.k) { + const imdbID = prompt("Enter IMDb ID. Leave empty to skip"); + let jsonVideoInfo; + if (imdbID) { + const movieInfo = await fetchMovieInfo(imdbID, args.k); + jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo); + } else { + jsonVideoInfo = buildVideoInfo(videoInfo); + } + const command = encodingCommandBuilder(jsonVideoInfo); + await writeShellScript(command); } else { - jsonVideoInfo = buildVideoInfo(videoInfo); + const jsonVideoInfo = buildVideoInfo(videoInfo); + const command = encodingCommandBuilder(jsonVideoInfo); + await writeShellScript(command); } - const command = encodingCommandBuilder(jsonVideoInfo); - await writeShellScript(command); } if (import.meta.main) {