]>
Commit | Line | Data |
---|---|---|
1 | import | |
2 | parseopt, | |
3 | strutils, | |
4 | tables | |
5 | ||
6 | import | |
7 | config, | |
8 | lib, | |
9 | types, | |
10 | youtube | |
11 | ||
12 | ||
13 | proc parseArguments(): CommandLineOptions = | |
14 | ||
15 | var | |
16 | searchQuery = "" | |
17 | options = to_table({ | |
18 | "musicOnly": false, | |
19 | "feelingLucky": false, | |
20 | "fullScreen": false, | |
21 | "download": false, | |
22 | "non-interactive": false | |
23 | }) | |
24 | ||
25 | for kind, key, value in getopt(): | |
26 | case kind | |
27 | of cmdArgument: | |
28 | searchQuery = key | |
29 | of cmdShortOption, cmdLongOption: | |
30 | case key | |
31 | of "m", "music": options["musicOnly"] = true | |
32 | of "l", "lucky": options["feelingLucky"] = true | |
33 | of "f", "full-screen": options["fullScreen"] = true | |
34 | of "d", "download": options["download"] = true | |
35 | of "n", "non-interactive": options["non-interactive"] = true | |
36 | of cmdEnd: discard | |
37 | ||
38 | if searchQuery == "": | |
39 | stderr.writeLine "NimCoon doesn't permit browsing. You must provide a search query." | |
40 | quit(1) | |
41 | ||
42 | (searchQuery, options) | |
43 | ||
44 | ||
45 | proc main() = | |
46 | let | |
47 | player = selectMediaPlayer() | |
48 | (searchQuery, options) = parseArguments() | |
49 | ||
50 | if(not isValidOptions(options)): | |
51 | quit(1) | |
52 | ||
53 | if searchQuery.startswith("http") or searchQuery.startswith("magnet"): | |
54 | if options["download"]: | |
55 | directDownload(sanitizeURL(searchQuery), options["musicOnly"]) | |
56 | else: | |
57 | directPlay(sanitizeURL(searchQuery), player, options) | |
58 | quit(0) | |
59 | ||
60 | let searchResults = getSearchResults(searchQuery) | |
61 | if options["non-interactive"]: | |
62 | for index, (title, url) in searchResults: | |
63 | echo title | |
64 | echo url | |
65 | echo "" | |
66 | quit(0) | |
67 | ||
68 | let numResults = min(limit, len(searchResults)) | |
69 | ||
70 | present(searchResults, options, (0, numResults-1), player) | |
71 | ||
72 | ||
73 | when isMainModule: | |
74 | main() |