From: Joseph Nuthalapati Date: Sun, 1 Dec 2019 22:12:33 +0000 (+0530) Subject: YouTube links can be played directly X-Git-Tag: 0.1.0~50 X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/commitdiff_plain/84d847803fe3c63601992d203b3a95f144918dce YouTube links can be played directly Signed-off-by: Joseph Nuthalapati --- diff --git a/TODO.org b/TODO.org index 1e88477..4481a37 100644 --- 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 diff --git a/clitube.nim b/clitube.nim index fb96d61..95c83a5 100644 --- a/clitube.nim +++ b/clitube.nim @@ -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