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,
|
||||
OMDBSeriesInfo,
|
||||
parsedVideoInfo,
|
||||
settings,
|
||||
VideoInfo,
|
||||
} from "./types.ts";
|
||||
import { VideoParser } from "./videoParser.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 {
|
||||
const cmd = "ffprobe";
|
||||
const args = [
|
||||
@@ -81,12 +99,13 @@ async function main() {
|
||||
// Parse arguments
|
||||
const args = parseArgs(Deno.args);
|
||||
if (!args.i) {
|
||||
console.log("Usage: videnc -i <video_file> -k <omdb_api_key>");
|
||||
console.log("Usage: videnc -i <video_file>");
|
||||
Deno.exit(1);
|
||||
}
|
||||
if (!args.k) {
|
||||
const app_settings = loadSettings();
|
||||
if (!app_settings.omdb_api_key) {
|
||||
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") {
|
||||
Deno.exit(1);
|
||||
@@ -101,11 +120,11 @@ async function main() {
|
||||
// Analyze video
|
||||
const videoInfo = analyzeVideo(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");
|
||||
let jsonVideoInfo;
|
||||
if (imdbID) {
|
||||
const movieInfo = await fetchMovieInfo(imdbID, args.k);
|
||||
const movieInfo = await fetchMovieInfo(imdbID, app_settings.omdb_api_key);
|
||||
jsonVideoInfo = buildVideoInfo(videoInfo, movieInfo);
|
||||
} else {
|
||||
jsonVideoInfo = buildVideoInfo(videoInfo);
|
||||
|
||||
@@ -230,3 +230,7 @@ export interface profile {
|
||||
preset: number;
|
||||
filmGrain: number;
|
||||
}
|
||||
|
||||
export interface settings {
|
||||
omdb_api_key: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user