14 proc parseArguments(): CommandLineOptions =
17 options = to_table({"musicOnly": false, "feelingLucky": false, "fullScreen": false, "download": false})
19 for kind, key, value in getopt():
23 of cmdShortOption, cmdLongOption:
25 of "m", "music": options["musicOnly"] = true
26 of "l", "lucky": options["feelingLucky"] = true
27 of "f", "full-screen": options["fullScreen"] = true
28 of "d", "download": options["download"] = true
31 (searchQuery, options)
34 proc isValidOptions*(options: Options): bool =
35 # Check for invalid combinations of options
36 var invalidCombinations = [("musicOnly", "fullScreen"), ("download", "fullScreen")]
38 for combination in invalidCombinations:
39 if options[combination[0]] and options[combination[1]]:
40 stderr.writeLine fmt"Incompatible options provided: {combination[0]} and {combination[1]}"
45 player = selectMediaPlayer()
46 (searchQuery, options) = parseArguments()
48 if(not isValidOptions(options)):
51 if searchQuery.startswith("http") or searchQuery.startswith("magnet"):
52 if options["download"]:
53 directDownload(sanitizeURL(searchQuery), options["musicOnly"])
55 directPlay(sanitizeURL(searchQuery), player, options)
58 let searchResults = getSearchResults(searchQuery)
59 let numResults = min(limit, len(searchResults))
61 present(searchResults, options, (0, numResults-1), player)