Play selected video using media player
authorJoseph Nuthalapati <njoseph@riseup.net>
Thu, 28 Nov 2019 18:14:34 +0000 (23:44 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Thu, 28 Nov 2019 18:24:11 +0000 (23:54 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
clitube.nim

index b6dda43787b43bab99ca04b2d33816f45ffac20d..9c14735f1791dab183f824209f9b2c92fd057e4d 100644 (file)
@@ -44,11 +44,19 @@ proc extractTitlesAndUrls(htmlFile: string): seq[SearchResult] =
     map(a => (a.attrs["title"], "https://www.youtube.com" & a.attrs["href"]))[..(limit-1)]
 
 proc presentVideoOptions(searchResults: seq[SearchResult]) =
-  echo "\n"
+  echo ""
   for index, (title, url) in searchResults:
     echo index, ". ", title.bold.fgMagenta, "\n", url.fgCyan, "\n"
 
-presentVideoOptions(
-  extractTitlesAndUrls(
-    getYoutubePage(
-      paramStr(1))))
+let searchResults = extractTitlesAndUrls(getYoutubePage(paramStr(1)))
+
+presentVideoOptions(searchResults)
+
+stdout.write "Choose video number: "
+var number: int = parseInt(readLine(stdin))
+
+var player = selectMediaPlayer()
+echo "\n", "Playing ", searchResults[number].title.bold.fgMagenta
+
+# Play the video in the media player
+discard execProcess(player & " " & searchResults[number].url)