Add option to play music only

Signed-off-by: Joseph Nuthalapati's avatarJoseph Nuthalapati <[email protected]>
parent 03a70308
......@@ -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
......
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}")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment