11 proc parseArguments(): CommandLineOptions =
14 options = to_table({"musicOnly": false, "feelingLucky": false, "fullScreen": false, "download": false})
16 for kind, key, value in getopt():
20 of cmdShortOption, cmdLongOption:
22 of "m", "music": options["musicOnly"] = true
23 of "l", "lucky": options["feelingLucky"] = true
24 of "f", "full-screen": options["fullScreen"] = true
25 of "d", "download": options["download"] = true
28 return (searchQuery, options)
31 proc isValidOptions*(options: Options): bool =
32 # Check for invalid combinations of options
33 var invalidCombinations = [("musicOnly", "fullScreen"), ("download", "fullScreen")]
34 for combination in invalidCombinations:
35 if options[combination[0]] and options[combination[1]]:
36 stderr.writeLine fmt"Incompatible options provided: {combination[0]} and {combination[1]}"
42 player = selectMediaPlayer()
43 (searchQuery, options) = parseArguments()
45 if(not isValidOptions(options)):
48 if searchQuery.startswith("https:") or searchQuery.startswith("magnet:"):
49 if options["download"]:
50 directDownload(sanitizeURL(searchQuery), options["musicOnly"])
52 directPlay(sanitizeURL(searchQuery), player, options)
55 let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery))
57 present(searchResults, options, (0, limit-1), player)