From 84d847803fe3c63601992d203b3a95f144918dce Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Mon, 2 Dec 2019 03:42:33 +0530 Subject: [PATCH] YouTube links can be played directly Signed-off-by: Joseph Nuthalapati --- TODO.org | 1 + clitube.nim | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 -- 2.43.0