-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
187 lines (169 loc) · 4.78 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { mkdirSync, readdirSync } from "fs";
import { join, dirname } from "path";
import { nanoid } from "nanoid";
import fetch from "node-fetch";
import Editly from "editly";
import config from "./config.json" assert { type: "json" };
import { fileURLToPath } from "url";
import gTTS from "gtts";
import { upload, comment } from "youtube-videos-uploader";
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
(async function () {
console.log("starting video protocol.");
const videos = await readdirSync(join(__dirname, "./bg-vids")).filter((v) =>
v.endsWith("mp4")
);
const rand = await random(1, videos.length);
const randVid = videos[rand];
const options = {
method: "GET",
headers: {
"X-RapidAPI-Key": config.JOKES_API_KEY,
"X-RapidAPI-Host": config.JOKES_API_HOST,
Accept: "application/json",
},
};
console.log("video protocol successful. Starting jokes protocol");
const { body: dadJokes } = await fetch(
"https://dad-jokes.p.rapidapi.com/random/joke?count=5",
options
).then((res) => res.json());
console.log("jokes protocol successful. starting voice protocol.");
const vidId = nanoid();
const path = join(__dirname, "vids", vidId);
mkdirSync(path);
for (let i = 0; i < dadJokes.length; i++) {
const gtts = new gTTS(
dadJokes[i].setup + " " + dadJokes[i].punchline,
"en-uk"
);
gtts.save(join(path, `voice-${i}.mp3`), (err, result) => {
if (err) console.error(err);
if (result) console.log(result);
});
}
/**
* @type {Editly.Config}
*/
const editlySpec = {
outPath: join(path, "video.mp4"),
width: 1080,
height: 1920,
// fast: true, // - for quick previewing
defaults: {
duration: 60,
layer: {
fontPath: join(__dirname, "fonts/inter.ttf"),
},
},
clips: [
{
duration: 60,
layers: [
{
type: "video",
path: join(__dirname, "bg-vids", randVid),
},
{
type: "title",
fontPath: join(__dirname, "fonts/Inter-ExtraBold.ttf"),
text: "DAD JOKES",
},
{
type: "subtitle",
text: dadJokes[0].setup + "\n" + dadJokes[0].punchline,
start: 0,
stop: 9,
},
{
type: "subtitle",
text: dadJokes[1].setup + "\n" + dadJokes[1].punchline,
start: 10,
stop: 19,
},
{
type: "subtitle",
text: dadJokes[2].setup + "\n" + dadJokes[2].punchline,
start: 20,
stop: 29,
},
{
type: "subtitle",
text: dadJokes[3].setup + "\n" + dadJokes[3].punchline,
start: 30,
stop: 39,
},
{
type: "subtitle",
text: dadJokes[4].setup + "\n" + dadJokes[4].punchline,
start: 40,
stop: 49,
},
],
},
],
audioTracks: [
{
path: join(__dirname, "vids", vidId, "voice-0.mp3"),
start: 0,
},
{
path: join(__dirname, "vids", vidId, "voice-1.mp3"),
start: 10,
},
{
path: join(__dirname, "vids", vidId, "voice-2.mp3"),
start: 20,
},
{
path: join(__dirname, "vids", vidId, "voice-3.mp3"),
start: 30,
},
{
path: join(__dirname, "vids", vidId, "voice-4.mp3"),
start: 40,
},
],
};
console.log("Voice protocol successful. Starting editly protocol.");
await Editly(editlySpec);
const video = {
path: join(path, "video.mp4"),
title: "Hilarious Dad Jokes #shorts #bot #generator",
description:
"Hilarious Dad Jokes made by a bot.\nfetched from https://dadjokes.io \nvisit https://github.com/MDxWARRIORxOP/YoutubeShortsGenerator for the source code.",
language: "en-uk",
tags: [
"github",
"english",
"dadjokes",
"jokes",
"memes",
"funny",
"fun",
"dad",
"generator",
"bot",
"automatic",
],
onSuccess: console.log,
skipProcessingWait: false,
onProgress: console.log,
publishType: "unlisted",
};
console.log("editly protocol successful. Starting video upload protocol.");
await upload(config.YOUTUBE_CREDENTIALS, [video]).then((link) => {
console.log(`video upload protocol successful. Link: ${link}.`);
const comment1 = {
link,
comment:
"This video was made by a bot.\nLink: https://github.com/MDxWARRIORxOP/YoutubeShortsGenerator",
};
comment(config.YOUTUBE_CREDENTIALS, [comment1]).then(console.log);
console.log("Shutting Down.");
});
})();