feat: store OMDB API key in config file instead of command line argument
This commit is contained in:
+24
-5
@@ -5,11 +5,29 @@ import {
|
|||||||
OMDBMovieInfo,
|
OMDBMovieInfo,
|
||||||
OMDBSeriesInfo,
|
OMDBSeriesInfo,
|
||||||
parsedVideoInfo,
|
parsedVideoInfo,
|
||||||
|
settings,
|
||||||
VideoInfo,
|
VideoInfo,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
import { VideoParser } from "./videoParser.ts";
|
import { VideoParser } from "./videoParser.ts";
|
||||||
import { encodingCommandBuilder } from "./commandBuilder.ts";
|
import { encodingCommandBuilder } from "./commandBuilder.ts";
|
||||||
|
|
||||||
|
const settings_file = Deno.env.get("HOME") + "/.config/videnc/settings.json";
|
||||||
|
|
||||||
|
function loadSettings(): settings {
|
||||||
|
if (!exists(settings_file)) {
|
||||||
|
const settings: settings = { omdb_api_key: "" };
|
||||||
|
Deno.writeFileSync(
|
||||||
|
settings_file,
|
||||||
|
new TextEncoder().encode(JSON.stringify(settings)),
|
||||||
|
);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
const settings: settings = JSON.parse(
|
||||||
|
new TextDecoder().decode(Deno.readFileSync(settings_file)),
|
||||||
|
);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
function analyzeVideo(videoFile: string): VideoInfo {
|
function analyzeVideo(videoFile: string): VideoInfo {
|
||||||
const cmd = "ffprobe";
|
const cmd = "ffprobe";
|
||||||
const args = [
|
const args = [
|
||||||
@@ -81,12 +99,13 @@ async function main() {
|
|||||||
// Parse arguments
|
// Parse arguments
|
||||||
const args = parseArgs(Deno.args);
|
const args = parseArgs(Deno.args);
|
||||||
if (!args.i) {
|
if (!args.i) {
|
||||||
console.log("Usage: videnc -i <video_file> -k <omdb_api_key>");
|
console.log("Usage: videnc -i <video_file>");
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
if (!args.k) {
|
const app_settings = loadSettings();
|
||||||
|
if (!app_settings.omdb_api_key) {
|
||||||
const confirm = prompt(
|
const confirm = prompt(
|
||||||
"No key entered. Are you sure you want to continue? (y/N)",
|
"No key found. Are you sure you want to continue? (y/N)",
|
||||||
);
|
);
|
||||||
if (confirm !== "y") {
|
if (confirm !== "y") {
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
@@ -101,11 +120,11 @@ 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);
|
||||||
if (args.k) {
|
if (app_settings.omdb_api_key) {
|
||||||
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, args.k);
|
const movieInfo = await fetchMovieInfo(imdbID, app_settings.omdb_api_key);
|
||||||
jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo);
|
jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo);
|
||||||
} else {
|
} else {
|
||||||
jsonVideoInfo = buildVideoInfo(videoInfo);
|
jsonVideoInfo = buildVideoInfo(videoInfo);
|
||||||
|
|||||||
@@ -230,3 +230,7 @@ export interface profile {
|
|||||||
preset: number;
|
preset: number;
|
||||||
filmGrain: number;
|
filmGrain: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface settings {
|
||||||
|
omdb_api_key: string;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user