-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcli.js
executable file
·100 lines (98 loc) · 2.68 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @github.com/motebaya - © 2023-10
* file: cli.js
* (CLI handler)
*
*/
import { ArgumentParser, RawTextHelpFormatter } from "argparse";
import { _Main, serverList } from "./main.js";
(async function () {
const parser = new ArgumentParser({
description:
"\tTIktok CLI downloader\n © Copyright: @github.com/motebaya - 2023",
formatter_class: RawTextHelpFormatter,
});
parser.add_argument("-u", "--url", {
type: "str",
metavar: "",
help: "tiktok video url",
});
parser.add_argument("-s", "--server", {
type: "str",
metavar: "",
choices: serverList,
help: `choose server list: ${JSON.stringify(serverList)
.replace(/"/g, "")
.replace(/,/g, ", ")}`,
});
parser.add_argument("-t", "--type", {
type: "str",
metavar: "",
choices: ["image", "music", "video"],
help: "choose existing media type: [image, video, music]",
});
/**
* additional.
* puppeter scraping are extended feature.
* the main are for downloading videos only from url.
*
*/
const group = parser.add_argument_group("additional");
group.add_argument("-S", "--search", {
type: "str",
metavar: "",
help: "search username/account using puppeteer by suplied query string. min:1, max:100",
});
group.add_argument("-d", "--dump", {
type: "str",
metavar: "",
help: "dump bulk user videos using puppeteer by suplied username. min: 35, max: 1000",
});
group.add_argument("-l", "--limit", {
type: "int",
metavar: "",
help: "limit arg number",
});
group.add_argument("-V", "--verbose", {
action: "store_true",
help: "debug mode on",
});
const args = parser.parse_args();
if (args.url && args.server && args.type) {
console.log(`\n ${parser.description}\n`);
_Main._extract({
url: args.url,
server: args.server.toLowerCase(),
type: args.type.toLowerCase(),
verbose: args.verbose,
});
} else {
/**
* grabber: dump -> save
* users search: `./{query}_{total}-search.json`
* videos lists: `./{username}_{total}-videolists.json`
*
*/
if (args.search || args.dump) {
if (args.search && args.limit) {
_Main.searchUsers({
query: args.search,
limit: args.limit,
verbose: args.verbose,
});
} else {
if (args.dump && args.limit) {
_Main.dumpVideos({
username: args.dump,
limit: args.limit,
verbose: args.verbose,
});
} else {
parser.print_help();
}
}
} else {
parser.print_help();
}
}
})();