Closure-RI commited on
Commit
9ac4a34
β€’
1 Parent(s): d579d2f

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +106 -0
index.js CHANGED
@@ -265,6 +265,83 @@ async function fetchCobaltOnly(url, opts = {}) {
265
 
266
 
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  // Fungsi untuk mendapatkan URL audio MP3 dari video YouTube
269
  async function getAudioMP3Url(videoUrl) {
270
  try {
@@ -848,6 +925,35 @@ app.get('/komiku', async (req, res) => {
848
  });
849
 
850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851
  /*******************
852
  ┏┓┏━┓┏━━━┓┏━┓┏━┓┏━━┓┏┓┏━┓┏┓╋┏┓
853
  ┃┃┃┏┛┃┏━┓┃┃┃┗┛┃┃┗┫┣┛┃┃┃┏┛┃┃╋┃┃
 
265
 
266
 
267
 
268
+ const servers = [
269
+ "https://co.eepy.today/",
270
+ "https://cdn1.meow.gs/",
271
+ "https://cdn2.meow.gs/",
272
+ "https://cdn3.meow.gs/",
273
+ "https://cdn4.meow.gs/",
274
+ "https://cdn5.meow.gs/",
275
+ ];
276
+
277
+ async function cobalt(config) {
278
+ try {
279
+ if (!(typeof config === "object")) {
280
+ throw new Error("Invalid config input, config must be a JSON object!");
281
+ }
282
+
283
+ config = {
284
+ url: config?.url || null,
285
+ videoQuality: config?.videoQuality || "720",
286
+ audioFormat: config?.audioFormat || "mp3",
287
+ audioBitrate: config?.audioBitrate || "128",
288
+ filenameStyle: config?.filenameStyle || "classic",
289
+ downloadMode: config?.downloadMode || "auto",
290
+ youtubeVideoCodec: config?.youtubeVideoCodec || "h264",
291
+ youtubeDubLang: config?.youtubeDubLang || "en",
292
+ alwaysProxy: config?.alwaysProxy || false,
293
+ disableMetadata: config?.disableMetadata || false,
294
+ tiktokFullAudio: config?.tiktokFullAudio || true,
295
+ tiktokH265: config?.tiktokH265 || true,
296
+ twitterGif: config?.twitterGif || true,
297
+ youtubeHLS: config?.youtubeHLS || false,
298
+ };
299
+
300
+ if (!config.url) {
301
+ throw new Error("Missing URL input!");
302
+ }
303
+
304
+ for (let i = 0; i < servers.length; i++) {
305
+ try {
306
+ console.log(`Trying server: ${servers[i]}`); // Log server yang dicoba
307
+ const response = await axios.post(servers[i], config, {
308
+ headers: {
309
+ accept: "application/json",
310
+ contentType: "application/json",
311
+ },
312
+ });
313
+
314
+ const data = response.data;
315
+ if (data.status === "error") {
316
+ throw new Error("Failed to fetch content from server.");
317
+ }
318
+
319
+ console.log(`Success with server: ${servers[i]}`); // Log server sukses
320
+ return {
321
+ success: true,
322
+ result: data,
323
+ };
324
+ } catch (error) {
325
+ if (i === servers.length - 1) {
326
+ // Jika sudah mencoba semua server
327
+ throw error;
328
+ }
329
+ console.warn(`Server ${servers[i]} failed. Trying next server...`); // Log server gagal
330
+ }
331
+ }
332
+ } catch (error) {
333
+ return {
334
+ success: false,
335
+ errors: error.message || error,
336
+ };
337
+ }
338
+ }
339
+
340
+
341
+
342
+
343
+
344
+
345
  // Fungsi untuk mendapatkan URL audio MP3 dari video YouTube
346
  async function getAudioMP3Url(videoUrl) {
347
  try {
 
925
  });
926
 
927
 
928
+ app.post("/cobalt", async (req, res) => {
929
+ const config = req.body;
930
+ try {
931
+ if (!config.url) {
932
+ return res.status(400).json({
933
+ success: false,
934
+ message: "Missing 'url' in the request body.",
935
+ });
936
+ }
937
+ const result = await cobalt(config);
938
+ if (result.success) {
939
+ return res.status(200).json(result);
940
+ } else {
941
+ return res.status(500).json({
942
+ success: false,
943
+ message: "Failed to process the request.",
944
+ errors: result,
945
+ });
946
+ }
947
+ } catch (error) {
948
+ res.status(500).json({
949
+ success: false,
950
+ message: "Internal server error.",
951
+ errors: error || error.message,
952
+ });
953
+ }
954
+ });
955
+
956
+
957
  /*******************
958
  ┏┓┏━┓┏━━━┓┏━┓┏━┓┏━━┓┏┓┏━┓┏┓╋┏┓
959
  ┃┃┃┏┛┃┏━┓┃┃┃┗┛┃┃┗┫┣┛┃┃┃┏┛┃┃╋┃┃