Continuously keep playing till I press "q"

Signed-off-by: Joseph Nuthalapati's avatarJoseph Nuthalapati <[email protected]>
parent cb5756d8
......@@ -45,7 +45,6 @@ proc presentVideoOptions*(searchResults: seq[SearchResult]) =
proc play*(player: string, args: openArray[string]) =
# poEchoCmd can be added to options for debugging
discard execProcess(player, args=args, options={poStdErrToStdOut, poUsePath})
quit(0)
func urlLongen(url: string): string =
url.replace("youtu.be/", "www.youtube.com/watch?v=")
......
......@@ -26,6 +26,7 @@ proc parseOptions(): CommandLineOptions =
return (searchQuery, musicOnly, feelingLucky, fullScreen)
proc main() =
let
player = selectMediaPlayer()
......@@ -36,24 +37,33 @@ proc main() =
let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery))
let number =
if feelingLucky: 0
proc getUserInput(): string =
if feelingLucky: "0"
else:
presentVideoOptions(searchResults)
stdout.styledWrite(fgYellow, "Choose video number: ")
parseInt(readLine(stdin))
styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
readLine(stdin)
# This is a pure function with no side effects
func buildArgs(): seq[string] =
func buildArgs(number: int): seq[string] =
var args = @[searchResults[number].url]
if musicOnly: args.add("--no-video")
if fullScreen: args.add("--fullscreen")
return args
# Play the video using the preferred/available media player
play(player, buildArgs())
while(true):
let userInput = getUserInput()
if userInput == "q":
break
let videoNumber = parseInt(userInput)
styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[videoNumber].title
# Play the video using the preferred/available media player
play(player, buildArgs(videoNumber))
if feelingLucky:
break
when isMainModule:
main()
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