ilhamdev commited on
Commit
1ccb9cc
·
verified ·
1 Parent(s): 601b94a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +33 -103
index.js CHANGED
@@ -15,6 +15,7 @@ const { File } = require('megajs')
15
  const { BingChat } = require("bing-chat-cjs-rnz");
16
  const path = require("path")
17
  const fs = require("fs")
 
18
  let fetch;
19
 
20
  (async () => {
@@ -104,39 +105,6 @@ throw new Error('Error: only audio/video files are supported');
104
  }
105
  }
106
 
107
- async function ytdlhamster(url) {
108
- try {
109
- // Melakukan permintaan GET menggunakan axios
110
- const response = await axios.get(`https://ytdl.hamsterlabs.de/?url=${encodeURIComponent(url)}`);
111
- const data = response.data;
112
-
113
- // Menggunakan cheerio untuk mem-parsing HTML
114
- const $ = cheerio.load(data);
115
- const downloadLinks = [];
116
-
117
- // Memproses setiap baris tabel kecuali header
118
- $('.formats tr').each((i, elem) => {
119
- if (i === 0) return; // Skip the header row
120
-
121
- // Mengambil informasi dari setiap kolom dalam baris
122
- const format = $(elem).find('td:nth-child(1) .format').text().trim();
123
- const quality = $(elem).find('td:nth-child(2)').text().trim();
124
- const bitrate = $(elem).find('td:nth-child(3)').text().trim();
125
- const container = $(elem).find('td:nth-child(4)').text().trim();
126
- const codecs = $(elem).find('td:nth-child(5)').text().trim();
127
- const downloadUrl = $(elem).find('td:nth-child(6) a').attr('href');
128
-
129
- // Menambahkan link unduhan ke daftar
130
- downloadLinks.push({ format, quality, bitrate, container, codecs, url: downloadUrl });
131
- });
132
-
133
- return downloadLinks;
134
- } catch (error) {
135
- console.error('Error fetching data:', error);
136
- throw error;
137
- }
138
- }
139
-
140
  // MEDIAFIRE DL
141
  async function mediafire(url) {
142
  return new Promise(async (resolve, reject) => {
@@ -229,77 +197,39 @@ async function fby2mate(url) {
229
  }
230
 
231
  async function ytAPI(url) {
232
- try {
233
- if (!/(?:https?:\/\/)?(?:www\.|music\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=|shorts\/|user\/\S+\/\S+\/)|youtu\.be\/)([\w-]{11})/.test(url)) throw "URL Invalid!!!"
234
- async function downloadVideoType(url, ftype) {
235
- // Step #1: Generate Download Hash
236
- const response1 = await axios.post(
237
- 'http://www.yt-download.org/api/json',
238
- {
239
- ftype,
240
- url,
241
- },
242
- {
243
- headers: {
244
- 'Content-Type': 'application/json',
245
- Accept: 'application/json',
246
- },
247
- }
248
- );
249
- //console.log(response1.data)
250
- const { hash } = response1?.data?.tasks[0];
251
-
252
- // Step #2: Start Download Task
253
- const response2 = await axios.post(
254
- 'http://www.yt-download.org/api/json',
255
- {
256
- hash,
257
- },
258
- {
259
- headers: {
260
- 'Content-Type': 'application/json',
261
- Accept: 'application/json',
262
- },
263
- }
264
- );
265
-
266
- const { taskId } = response2?.data;
267
-
268
- // Step #3: Check Download Task Status
269
- let response3;
270
- do {
271
- response3 = await axios.post(
272
- 'http://www.yt-download.org/api/json/task',
273
- {
274
- taskId,
275
- },
276
- {
277
- headers: {
278
- 'Content-Type': 'application/json',
279
- Accept: 'application/json',
280
- },
281
- }
282
- );
283
-
284
- //console.log(response3.data);
285
-
286
- await new Promise((resolve) => setTimeout(resolve, 5000)); // wait 5 seconds before checking again
287
- } while (response3.data.status !== 'finished');
288
-
289
- return response3;
290
- }
291
- const mp4Response = await downloadVideoType(url, 'mp4');
292
- const mp3Response = await downloadVideoType(url, 'mp3');
293
-
294
- return {
295
- video: mp4Response?.data,
296
- audio: mp3Response?.data,
297
- };
298
- } catch (error) {
299
- console.error(error);
300
- throw error;
301
- }
302
  }
 
303
 
304
 
305
  // Fungsi untuk mengkonversi video dari YouTube
 
15
  const { BingChat } = require("bing-chat-cjs-rnz");
16
  const path = require("path")
17
  const fs = require("fs")
18
+ const ytdlp = require('yt-dlp-exec');
19
  let fetch;
20
 
21
  (async () => {
 
105
  }
106
  }
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  // MEDIAFIRE DL
109
  async function mediafire(url) {
110
  return new Promise(async (resolve, reject) => {
 
197
  }
198
 
199
  async function ytAPI(url) {
200
+ try {
201
+ // Fetch the video info
202
+ const info = await ytdlp.getInfo(url);
203
+
204
+ // Extract necessary information
205
+ const videoDetails = {
206
+ title: info.title,
207
+ url: url,
208
+ formats: info.formats.map(format => ({
209
+ format_id: format.format_id,
210
+ ext: format.ext,
211
+ resolution: format.resolution,
212
+ url: format.url
213
+ }))
214
+ };
215
+
216
+ // Filter MP4 and MP3 formats
217
+ const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
218
+ const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
219
+
220
+ const result = {
221
+ title: videoDetails.title,
222
+ url: videoDetails.url,
223
+ mp4Url: mp4Format ? mp4Format.url : null,
224
+ mp3Url: mp3Format ? mp3Format.url : null
225
+ };
226
+
227
+ return result;
228
+ } catch (error) {
229
+ console.error('Error fetching video info:', error);
230
+ throw error;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  }
232
+ }
233
 
234
 
235
  // Fungsi untuk mengkonversi video dari YouTube