]>
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, | |
5f9cdfef JN |
22 | "nonInteractive": false, |
23 | "autoPlay": false | |
a2d28598 | 24 | }) |
121e06b2 | 25 | |
5f9cdfef | 26 | # Non-interactive/Global options |
121e06b2 JN |
27 | for kind, key, value in getopt(): |
28 | case kind | |
29 | of cmdArgument: | |
30 | searchQuery = key | |
31 | of cmdShortOption, cmdLongOption: | |
32 | case key | |
6f161e0b JN |
33 | of "m", "music": options["musicOnly"] = true |
34 | of "l", "lucky": options["feelingLucky"] = true | |
35 | of "f", "full-screen": options["fullScreen"] = true | |
36 | of "d", "download": options["download"] = true | |
5f9cdfef JN |
37 | of "n", "non-interactive": options["nonInteractive"] = true |
38 | of "a", "auto-play": options["autoPlay"] = true | |
6f161e0b JN |
39 | of cmdEnd: discard |
40 | ||
26229fac JN |
41 | if searchQuery == "": |
42 | stderr.writeLine "NimCoon doesn't permit browsing. You must provide a search query." | |
43 | quit(1) | |
44 | ||
55b0cae7 | 45 | (searchQuery, options) |
121e06b2 | 46 | |
6f161e0b | 47 | |
121e06b2 JN |
48 | proc main() = |
49 | let | |
50 | player = selectMediaPlayer() | |
6f161e0b JN |
51 | (searchQuery, options) = parseArguments() |
52 | ||
53 | if(not isValidOptions(options)): | |
54 | quit(1) | |
121e06b2 | 55 | |
25f5a034 | 56 | if searchQuery.startswith("http") or searchQuery.startswith("magnet"): |
9a8ef4ad | 57 | if options["download"]: |
811928a7 | 58 | directDownload(sanitizeURL(searchQuery), options["musicOnly"]) |
9a8ef4ad | 59 | else: |
d36e2201 | 60 | directPlay(sanitizeURL(searchQuery), player, options) |
9e6b8568 | 61 | quit(0) |
121e06b2 | 62 | |
e08e5cbe | 63 | let searchResults = getSearchResults(searchQuery) |
5f9cdfef | 64 | if options["nonInteractive"]: |
26229fac JN |
65 | for index, (title, url) in searchResults: |
66 | echo title | |
67 | echo url | |
68 | echo "" | |
69 | quit(0) | |
70 | ||
fac67037 | 71 | let numResults = min(limit, len(searchResults)) |
121e06b2 | 72 | |
fac67037 | 73 | present(searchResults, options, (0, numResults-1), player) |
d807245d | 74 | |
a2319a3f | 75 | |
d65a1dcf JN |
76 | when isMainModule: |
77 | main() |