8 proc parseOptions(): CommandLineOptions =
15 for kind, key, value in getopt():
19 of cmdShortOption, cmdLongOption:
21 of "m", "music": musicOnly = true
22 of "l", "lucky": feelingLucky = true
23 of "f", "full-screen": fullScreen = true
27 return (searchQuery, musicOnly, feelingLucky, fullScreen)
31 player = selectMediaPlayer()
32 (searchQuery, musicOnly, feelingLucky, fullScreen) = parseOptions()
34 if searchQuery.startswith("https:") or searchQuery.startswith("magnet:"):
35 directPlay(searchQuery, player)
37 let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery))
42 presentVideoOptions(searchResults)
43 stdout.styledWrite(fgYellow, "Choose video number: ")
44 parseInt(readLine(stdin))
46 styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
48 # This is a pure function with no side effects
49 func buildArgs(): seq[string] =
50 var args = @[searchResults[number].url]
51 if musicOnly: args.add("--no-video")
52 if fullScreen: args.add("--fullscreen")
55 # Play the video using the preferred/available media player
56 play(player, buildArgs())