diff --git a/src/main.ts b/src/main.ts index b656c9a..e876047 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 -k "); + console.log("Usage: videnc -i "); 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); diff --git a/src/types.ts b/src/types.ts index 210a5e5..7b68b39 100644 --- a/src/types.ts +++ b/src/types.ts @@ -230,3 +230,7 @@ export interface profile { preset: number; filmGrain: number; } + +export interface settings { + omdb_api_key: string; +}