refactor: make OMDB API key a command line argument instead of environment variable
This commit is contained in:
+17
-4
@@ -44,10 +44,10 @@ function buildVideoInfo(
|
|||||||
|
|
||||||
async function fetchMovieInfo(
|
async function fetchMovieInfo(
|
||||||
imdbID: string,
|
imdbID: string,
|
||||||
|
apiKey: string,
|
||||||
): Promise<OMDBMovieInfo | OMDBSeriesInfo> {
|
): Promise<OMDBMovieInfo | OMDBSeriesInfo> {
|
||||||
const omdbAPIKey = Deno.env.get("OMDB_API_KEY");
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`https://www.omdbapi.com/?i=${imdbID}&apikey=${omdbAPIKey}`,
|
`https://www.omdbapi.com/?i=${imdbID}&apikey=${apiKey}`,
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
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>");
|
console.log("Usage: deno run main.ts -i <video_file>");
|
||||||
Deno.exit(1);
|
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
|
// Check if file exists
|
||||||
const videoFile: string = String(args.i);
|
const videoFile: string = String(args.i);
|
||||||
if (!await exists(videoFile)) {
|
if (!await exists(videoFile)) {
|
||||||
@@ -93,17 +101,22 @@ async function main() {
|
|||||||
// Analyze video
|
// Analyze video
|
||||||
const videoInfo = analyzeVideo(videoFile);
|
const videoInfo = analyzeVideo(videoFile);
|
||||||
videoInfo.format.filename = resolve(videoFile);
|
videoInfo.format.filename = resolve(videoFile);
|
||||||
//const imdbID = "tt0108333";
|
if (args.k) {
|
||||||
const imdbID = prompt("Enter IMDb ID. Leave empty to skip");
|
const imdbID = prompt("Enter IMDb ID. Leave empty to skip");
|
||||||
let jsonVideoInfo;
|
let jsonVideoInfo;
|
||||||
if (imdbID) {
|
if (imdbID) {
|
||||||
const movieInfo = await fetchMovieInfo(imdbID);
|
const movieInfo = await fetchMovieInfo(imdbID, args.k);
|
||||||
jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo);
|
jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo);
|
||||||
} else {
|
} else {
|
||||||
jsonVideoInfo = buildVideoInfo(videoInfo);
|
jsonVideoInfo = buildVideoInfo(videoInfo);
|
||||||
}
|
}
|
||||||
const command = encodingCommandBuilder(jsonVideoInfo);
|
const command = encodingCommandBuilder(jsonVideoInfo);
|
||||||
await writeShellScript(command);
|
await writeShellScript(command);
|
||||||
|
} else {
|
||||||
|
const jsonVideoInfo = buildVideoInfo(videoInfo);
|
||||||
|
const command = encodingCommandBuilder(jsonVideoInfo);
|
||||||
|
await writeShellScript(command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
|
|||||||
Reference in New Issue
Block a user