refactor: make OMDB API key a command line argument instead of environment variable
This commit is contained in:
+24
-11
@@ -44,10 +44,10 @@ function buildVideoInfo(
|
||||
|
||||
async function fetchMovieInfo(
|
||||
imdbID: string,
|
||||
apiKey: string,
|
||||
): Promise<OMDBMovieInfo | OMDBSeriesInfo> {
|
||||
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 <video_file>");
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user