Improve selection of media player
authorJoseph Nuthalapati <njoseph@riseup.net>
Sat, 5 Oct 2019 08:26:36 +0000 (13:56 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sat, 5 Oct 2019 08:26:36 +0000 (13:56 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
cli_tube.nim

index ccf09ae0c0ad618aabc4b26ab9c66732fd1eb6fa..3ed32b0ec78e70edbd5c6dc1ae348a45af0a238d 100644 (file)
@@ -17,11 +17,13 @@ let supportedPlayers = @["mpv", "mplayer", "vlc"]
 
 type SearchResult = tuple[title: string, url: string]
 
-proc findSupportedPlayer(): string =
-  for player in supported_players:
-    let playerBin = execProcess("which " & player)
-    if playerBin.len != 0:
-      return strip(playerBin)
+proc selectMediaPlayer(): string =
+  let availablePlayers = filterIt(supportedPlayers, execProcess("which " & it).len != 0)
+  if len(availablePlayers) == 0:
+    echo "Please install one of the supported media players: ", supportedPlayers
+    raise newException(OSError, "No supported media player found")
+  else:
+    return availablePlayers[0]
 
 proc getYoutubePage(searchQuery: string): string =
   let queryParam = encodeUrl(searchQuery)