YouTube links can be played directly
authorJoseph Nuthalapati <njoseph@riseup.net>
Sun, 1 Dec 2019 22:12:33 +0000 (03:42 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sun, 1 Dec 2019 22:12:33 +0000 (03:42 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
TODO.org
clitube.nim

index 1e8847736f7cc2ad4573bab2ac98a8b71731c389..4481a3721628860ce7849fffc3897896ee35ad35 100644 (file)
--- a/TODO.org
+++ b/TODO.org
@@ -6,3 +6,4 @@
 * TODO Preferences should go into a config file
 * TODO Terminal color themes?
 * TODO Get rid of temp file or make one temp file per user
+* TODO Use cligen to create a proper CLI
index fb96d616283302740d7f1b46ad8add32c459b565..95c83a5804c988669d878b1e99ac13e576606470 100644 (file)
@@ -42,14 +42,20 @@ proc presentVideoOptions(searchResults: seq[SearchResult]) =
   for index, (title, url) in searchResults:
     styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"
 
-let searchResults = extractTitlesAndUrls(getYoutubePage(paramStr(1)))
+let input = paramStr(1)
+let player = selectMediaPlayer()
+
+if "https://www.youtube.com" in input:
+  discard execProcess(player & " " & input)
+  quit(0)
+
+let searchResults = extractTitlesAndUrls(getYoutubePage(input))
 
 presentVideoOptions(searchResults)
 
 stdout.styledWrite(fgYellow, "Choose video number: ")
 var number: int = parseInt(readLine(stdin))
 
-var player = selectMediaPlayer()
 styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
 
 # Play the video using the preferred/available media player