Add option to feel lucky!
authorJoseph Nuthalapati <njoseph@riseup.net>
Sat, 14 Dec 2019 13:29:07 +0000 (18:59 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sat, 14 Dec 2019 13:31:27 +0000 (19:01 +0530)
- Skip selection prompt and play the first result

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
README.md
clitube.nim

index bcf6ffdf3d39ddd5758220a0546b8aa801bbcff1..c0e53e4b517bb72f67c40cad7386a31929a91100 100644 (file)
--- a/README.md
+++ b/README.md
@@ -45,13 +45,17 @@ clitube emacs
 
 # If your search query has multiple words, use quotes
 clitube 'nim lang'
+
+# Advanced: Play audio of the first search result
+clitube -m -l "counting stars"
 ```
 
 ### Commandline arguments
 
-| **Arguments** | **Explanation**           |
-|----------------|---------------------------|
-| -m, --music    | Play Music only, no video |
+| **Arguments** | **Explanation**                            |
+|---------------|--------------------------------------------|
+| -m, --music   | Play Music only, no video                  |
+| -l, --lucky   | Try your luck with the first search result |
 
 ## Development
 
index a9642916326dfd6a13a472b6045c74d3cade3656..50a3f67a17838f87c3f8b355a5bfdd2df37bce34 100644 (file)
@@ -42,6 +42,7 @@ let player = selectMediaPlayer()
 
 var searchQuery = ""
 var musicOnly = false
+var feelingLucky = false
 
 for kind, key, value in getopt():
   case kind
@@ -50,6 +51,7 @@ for kind, key, value in getopt():
   of cmdShortOption, cmdLongOption:
     case key
     of "m", "music": musicOnly = true
+    of "l", "lucky": feelingLucky = true
   of cmdEnd:
     discard
 
@@ -61,10 +63,13 @@ if "https://www.youtube.com" in searchQuery:
 
 let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery))
 
-presentVideoOptions(searchResults)
-
-stdout.styledWrite(fgYellow, "Choose video number: ")
-let number = parseInt(readLine(stdin))
+let number =
+  if feelingLucky:
+    0
+  else:
+    presentVideoOptions(searchResults)
+    stdout.styledWrite(fgYellow, "Choose video number: ")
+    parseInt(readLine(stdin))
 
 styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title