From f7735b43cbeb05c3e30cc9d2d0df3197fa1c0eb9 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Fri, 10 Jan 2020 22:59:29 +0530 Subject: [PATCH] Store player config options in a hashtable Signed-off-by: Joseph Nuthalapati --- README.md | 2 +- config.nim | 21 +++++++++++++++++++++ nimcoon.nim | 10 ++++------ preferences.nim | 9 --------- 4 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 config.nim delete mode 100644 preferences.nim diff --git a/README.md b/README.md index 2823d1e..daf4ca6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Nim Coon +# NimCoon Play videos from YouTube and PeerTube from the command line using your preferred desktop media player. diff --git a/config.nim b/config.nim new file mode 100644 index 0000000..f55bc9d --- /dev/null +++ b/config.nim @@ -0,0 +1,21 @@ +import tables + +# Your configuration here. + +# Supported video players in order of preference. +# Should be able to play YouTube videos directly. +let supportedPlayers* = ["mpv", "cvlc"] + +# Only show these many results +let limit* = 10 + +# Some NimCoon options mapped to player options +let playerOptions* = { "mpv": { + "musicOnly": "--no-video", + "fullScreen": "--fullscreen" + }.toTable, + "cvlc": { + "musicOnly": "--no-video", + "fullScreen": "--fs" + }.toTable + }.toTable diff --git a/nimcoon.nim b/nimcoon.nim index f69813d..c838b34 100644 --- a/nimcoon.nim +++ b/nimcoon.nim @@ -10,10 +10,11 @@ import std/[terminal], strtabs, strutils, + tables, uri, xmltree -import preferences +import config type SearchResult = tuple[title: string, url: string] @@ -100,13 +101,10 @@ proc main() = var command = @[player, searchResults[number].url] if musicOnly: - command.add("--no-video") + command.add(playerOptions[player]["musicOnly"]) if fullScreen: - if player == "cvlc": - command.add("--fullscreen") - if player == "mpv": - command.add("--fs") + command.add(playerOptions[player]["fullScreen"]) # Play the video using the preferred/available media player play(command.join(" ")) diff --git a/preferences.nim b/preferences.nim deleted file mode 100644 index a9ef411..0000000 --- a/preferences.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Your preferences here. - -# Supported video players in order of preference. -# Should be able to play YouTube videos directly. -let supportedPlayers* = ["mpv", "cvlc"] - -# Only show these many results -let limit* = 10 - -- 2.43.0