-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
54 lines (44 loc) · 1.36 KB
/
main.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
const fs = require("fs");
const util = require("util");
const readdir = util.promisify(fs.readdir);
const webdriver = require("selenium-webdriver");
const firefox = require("selenium-webdriver/firefox");
const cookiesModule = require("./cookies/cookies");
const worker = require("./worker");
const includedFiles = ".mp4";
//const folder = "tok-tok-bot/media";
const folder = "/Users/sepezho/Code/projects/tik-tok-bot/media";
const bot = async () => {
const options = new firefox.Options();
// options.addArguments("-headless");
options.addArguments("-standalone");
const driver = new webdriver.Builder()
.forBrowser("firefox")
.setFirefoxOptions(options)
.build();
await driver.get("https://www.tiktok.com");
for (const cookie of cookiesModule.cookies) {
if (cookie.name)
await driver
.manage()
.addCookie({ name: cookie.name, value: cookie.value });
}
await driver.get("https://www.tiktok.com/upload?lang=en");
const videoUrls = [];
let elements = 0;
await readdir(folder, async (_, files) => {
if (files)
await Promise.all(
files
.filter((s) => s.includes(includedFiles))
.map(async (file) => {
videoUrls.push(`${folder}/${file}`);
elements++;
if (!files.filter((s) => s.includes(includedFiles))[elements]) {
await worker(videoUrls, elements, webdriver, driver);
}
})
);
});
};
bot();