X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/blobdiff_plain/d65a1dcf24e9c17cea89385c78b1c39c314f0f97..9e6b85681599066dee4fca75097286e5c823875b:/nimcoon.nim diff --git a/nimcoon.nim b/nimcoon.nim index 5c2dc08..8b1ba59 100644 --- a/nimcoon.nim +++ b/nimcoon.nim @@ -3,6 +3,7 @@ import std/[terminal], strutils +import config import lib proc parseOptions(): CommandLineOptions = @@ -26,6 +27,7 @@ proc parseOptions(): CommandLineOptions = return (searchQuery, musicOnly, feelingLucky, fullScreen) + proc main() = let player = selectMediaPlayer() @@ -33,27 +35,40 @@ proc main() = if searchQuery.startswith("https:") or searchQuery.startswith("magnet:"): directPlay(searchQuery, player) + quit(0) let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery)) - let number = - if feelingLucky: 0 + proc getUserInput(): string = + if feelingLucky: "0" else: - presentVideoOptions(searchResults) + presentVideoOptions(searchResults[..(limit-1)]) 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 == "all": + for number in 0..(len(searchResults)): + play(player, buildArgs(number), searchResults[number].title) + + if userInput == "q": + break + + # Play the video using the preferred/available media player + let videoNumber = parseInt(userInput) + play(player, buildArgs(videoNumber), searchResults[videoNumber].title) + if feelingLucky: + break + when isMainModule: main()