]> njoseph.me Git - nimcoon.git/commitdiff
Add option to play music only
authorJoseph Nuthalapati <njoseph@riseup.net>
Fri, 13 Dec 2019 12:58:31 +0000 (18:28 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Fri, 13 Dec 2019 13:25:44 +0000 (18:55 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
README.md
clitube.nim

index b851c090ea4b1516c5b7c489806ccef0c2dea20e..d0fdffa63bfbc98090146f12f50f4f55478c88f7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ only the standard library.
 
 - [x] Search for videos using keywords
 - [x] Stream videos
-- [ ] Stream music
+- [x] Stream music
 - [ ] Download videos
 - [ ] Configuration options
     - [ ] Choice of video players
@@ -47,6 +47,14 @@ clitube emacs
 clitube 'nim lang'
 ```
 
+### Commandline arguments
+
+|----------------|---------------------------|
+| ***Arguments** | **Explanation**           |
+|----------------|---------------------------|
+| -m, --music    | Play Music only, no video |
+|----------------|---------------------------|
+
 ## Development
 
 One-liner for compiling and running
index 0c21a941bbaa8d30f206b2eded4371c134f3a277..3714c13612433ed295690aec1a41063ecfde2110 100644 (file)
@@ -1,6 +1,6 @@
 import htmlparser
 import httpClient
-import os
+import parseopt
 import osproc
 import sequtils, sugar
 import strformat
@@ -38,14 +38,29 @@ proc presentVideoOptions(searchResults: seq[SearchResult]) =
   for index, (title, url) in searchResults:
     styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"
 
-let input = paramStr(1)
 let player = selectMediaPlayer()
 
-if "https://www.youtube.com" in input:
-  discard execProcess(&"{player} {input}")
+var searchQuery = ""
+var musicOnly = false
+
+for kind, key, value in getopt():
+  case kind
+  of cmdArgument:
+     searchQuery = key
+  of cmdShortOption, cmdLongOption:
+    case key
+    of "m", "music": musicOnly = true
+  of cmdEnd:
+    discard
+
+let noVideo = if musicOnly: "--no-video" else: ""
+
+if "https://www.youtube.com" in searchQuery:
+  discard execProcess(&"{player} {searchQuery}")
   quit(0)
 
-let searchResults = extractTitlesAndUrls(getYoutubePage(input))
+
+let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery))
 
 presentVideoOptions(searchResults)
 
@@ -55,4 +70,4 @@ let number = parseInt(readLine(stdin))
 styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
 
 # Play the video using the preferred/available media player
-discard execProcess(&"{player}  {searchResults[number].url}")
+discard execProcess(&"{player} {noVideo} {searchResults[number].url}")