From 73fa8b09252bcf10b3f6e2cb93ccad74bc05c01d Mon Sep 17 00:00:00 2001 From: Esa Kataja Date: Sun, 16 Nov 2025 15:40:18 +0200 Subject: [PATCH] feat: add CLI argument handling and build script - Added command-line argument parsing to accept input file path instead of hardcoded value - Added build task to compile standalone executable with deno compile - Added usage message for incorrect invocation --- LICENSE | 20 ++++++++++++++++++++ README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ deno.json | 3 ++- src/main.ts | 12 ++++++++---- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..23799b7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2025 Kessinen + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b81ca26 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# dvdsubconvert + +A command-line tool built with Deno to extract, convert, and remux DVD subtitles +from MKV video files into SRT format, then combine them back into a new MKV +file. + +## Prerequisites + +Ensure the following tools are installed and available in your PATH: + +- [MKVToolNix](https://mkvtoolnix.download/) (provides `mkvmerge` and + `mkvextract`) +- [FFmpeg](https://ffmpeg.org/) +- [vobsub2srt](https://github.com/ruediger/VobSub2SRT) (for converting VobSub + subtitles to SRT) + +## Installation + +Clone the repository and ensure Deno is installed +([Deno installation guide](https://deno.land/manual/getting_started/installation)). + +## Usage + +Run the tool with a single MKV file as input: + +```bash +deno run --allow-run --allow-write --allow-read src/main.ts input.mkv +``` + +The tool will: + +1. Analyze the MKV file for subtitle tracks. +2. Extract supported subtitle languages. +3. Convert VobSub subtitles to SRT format. +4. Remux the SRT subtitles into a new MKV file named `subit.mkv`. + +Supported languages (ISO 639-1 codes): + +- English (en) +- Finnish (fi) + +## Output + +- `subit.mkv`: The resulting MKV file with converted SRT subtitles. +- Temporary files (`.srt`, `.idx`, `.sub`) are cleaned up automatically. + +## License + +[Include license info from LICENSE file] diff --git a/deno.json b/deno.json index a3430a7..3d44e96 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,7 @@ { "tasks": { - "dev": "deno run --watch --allow-run --allow-write --allow-read src/main.ts" + "dev": "deno run --watch --allow-run --allow-write --allow-read src/main.ts", + "build": "deno compile --allow-run --allow-write --allow-read --output dist/dvdsubconvert src/main.ts" }, "imports": { "@std/assert": "jsr:@std/assert@1" diff --git a/src/main.ts b/src/main.ts index 3082927..d8cbc14 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,5 @@ import { videoFile } from "./types.ts"; -const input = "/home/esa/Videos/tmp/3MUSKETEERS_D1_PAL/B3_t00.mkv"; - // TODO: Check if mkvmerge, ffmpeg and vobsub2srt are installed. const lang_codes = { @@ -73,7 +71,7 @@ function cleanUp(languages: Record) { } } -async function main() { +async function main(input: string) { const mkvmerge_output = subtitlesLookup(input); const languages_in_file: Record = {}; for (const track of mkvmerge_output.tracks) { @@ -139,7 +137,13 @@ async function main() { } if (import.meta.main) { - main().catch((e) => { + const args = Deno.args; + if (args.length !== 1) { + console.error("Usage: deno run main.ts "); + Deno.exit(1); + } + const input = args[0]; + main(input).catch((e) => { console.error(e); Deno.exit(1); });