Better use of execProcess options
authorJoseph Nuthalapati <njoseph@riseup.net>
Fri, 10 Jan 2020 18:27:42 +0000 (23:57 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Fri, 10 Jan 2020 18:27:42 +0000 (23:57 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
.gitlab-ci.yml
nimcoon.nim

index 7597d89e387da1f12a0be2ac3de0347653fdccc7..727e2f2f3f5729d076652a36f70fc14ddca2c776 100644 (file)
@@ -6,7 +6,7 @@ stages:
 compile:
   stage: build
   script:
-    - nim c -d:ssl -d:release nimcoon.nim
+    - nim c -d:ssl -d:release nimcoon.nim && strip nimcoon
   artifacts:
     paths:
       - nimcoon
index c838b343f66568c6e054d4f05de5bd7c55e20590..f47b249b1de9abb4e1974e77b299de2787fe5797 100644 (file)
@@ -1,7 +1,6 @@
 import
   htmlparser,
   httpClient,
-  logging,
   parseopt,
   osproc,
   sequtils,
@@ -20,9 +19,6 @@ type
   SearchResult = tuple[title: string, url: string]
   CommandLineOptions = tuple[searchQuery: string, musicOnly: bool, feelingLucky: bool, fullScreen: bool]
 
-let logger = newConsoleLogger()
-setLogFilter(lvlInfo)
-
 proc selectMediaPlayer(): string =
   let availablePlayers = filterIt(supportedPlayers, execProcess("which " & it).len != 0)
   if len(availablePlayers) == 0:
@@ -68,16 +64,15 @@ proc presentVideoOptions(searchResults: seq[SearchResult]) =
   for index, (title, url) in searchResults:
     styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"
 
-proc play(command: string) =
-  logger.log(lvlDebug, &"Executing: ${command}")
-  discard execProcess(command)
+proc play(player: string, args: openArray[string]) =
+  discard execProcess(player, args=args, options={poStdErrToStdOut, poUsePath, poEchoCmd})
   quit(0)
 
 proc directPlay(searchQuery: string, player: string) =
-  if "watch?" in searchQuery or "videos/watch" in searchQuery :
-    play(&"{player} {searchQuery}")
+  if "watch?" in searchQuery or "videos/watch" in searchQuery:
+    play(player, args=[searchQuery])
   elif searchQuery.startswith("magnet:"):
-    play(&"peerflix \"{searchQuery}\" --{player}")
+    play("peerflix", args=[searchQuery, &"--{player}"])
 
 proc main() =
   let
@@ -98,15 +93,15 @@ proc main() =
 
   styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
 
-  var command = @[player, searchResults[number].url]
+  var args = @[searchResults[number].url]
 
   if musicOnly:
-    command.add(playerOptions[player]["musicOnly"])
+    args.add(playerOptions[player]["musicOnly"])
 
   if fullScreen:
-    command.add(playerOptions[player]["fullScreen"])
+    args.add(playerOptions[player]["fullScreen"])
 
   # Play the video using the preferred/available media player
-  play(command.join(" "))
+  play(player, args)
 
 main()