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