From 4992a8684c5d129bba9297e438d6258dd6d5a2d8 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Mon, 27 Mar 2023 12:46:35 +1300 Subject: [PATCH] De-hardcode mpg123 The MPEG player is no longer hard-coded as mpg123, and now customizable by changing the enum `DEFAULT_MPEGPLAYER`. --- main.d | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.d b/main.d index 71c7cdc..24c670b 100644 --- a/main.d +++ b/main.d @@ -33,6 +33,7 @@ import dini; enum VERSION = "0.1.0"; enum DEFAULT_CONFIGPATH = "~/.config/esv.conf"; +enum DEFAULT_MPEGPLAYER = "mpg123"; enum DEFAULT_PAGER = "less"; enum ENV_CONFIG = "ESV_CONFIG"; @@ -170,13 +171,23 @@ int main(string[] args) if (optAudio) { // check for mpg123 - if (executeShell("which mpg123 >/dev/null 2>&1").status > 0) { - panic("mpg123 is required for audio mode; cannot continue"); + if (executeShell("which " ~ DEFAULT_MPEGPLAYER ~ " >/dev/null 2>&1").status > 0) { + panic(DEFAULT_MPEGPLAYER ~ " is required for audio mode; cannot continue"); return 1; } else { string tmpf = esv.getAudioVerses(args[1], args[2]); + string mpegPlayer; + // esv has built-in support for mpg123 and mpv + // other players will work, just recompile with + // the DEFAULT_MPEGPLAYER enum set differently + if (DEFAULT_MPEGPLAYER == "mpg123") + mpegPlayer = DEFAULT_MPEGPLAYER ~ " -q "; + else if (DEFAULT_MPEGPLAYER == "mpv") + mpegPlayer = DEFAULT_MPEGPLAYER ~ " --msg-level=all=no "; + else + mpegPlayer = DEFAULT_MPEGPLAYER ~ " "; // spawn mpg123 - executeShell("mpg123 -q " ~ tmpf); + executeShell(mpegPlayer ~ tmpf); return 0; } }