Closure-RI commited on
Commit
9ff5f37
·
verified ·
1 Parent(s): a68e9c1

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +23 -1
index.js CHANGED
@@ -246,12 +246,34 @@ function generateRandomName(length) {
246
  return randomName;
247
  }
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  // Fungsi untuk mendapatkan URL audio MP3 dari video YouTube
250
  async function getAudioMP3Url(videoUrl) {
251
  try {
 
252
  const requestData = {"url":videoUrl,"vQuality":"360","filenamePattern":"pretty","isAudioOnly":"true"}
253
  const config = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36', 'Referer': 'https://cobalt.tools/' } };
254
- const { data: video } = await axios.post('https://kityune.imput.net/api/json', requestData, config);
 
 
255
  const path_audio = path.join(tempDir, generateRandomName(10) + '.mp3');
256
  const id_video = await GetId(videoUrl);
257
  const infoVids = await getVideoDetailsWithApi(id_video);
 
246
  return randomName;
247
  }
248
 
249
+
250
+ async function fetchCobaltOnly(url, opts = {}) {
251
+ try {
252
+ const response = await axios.post('https://kityune.imput.net/api/json', { url, ...opts }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } } );
253
+ return response.data;
254
+ } catch (error) {
255
+ if (error.response) {
256
+ const contentType = error.response.headers['content-type'];
257
+ if (contentType && contentType.includes('json')) {
258
+ throw error.response.data.message || 'An error occurred';
259
+ }
260
+ throw error.response.statusText;
261
+ }
262
+ throw error.message;
263
+ }
264
+ }
265
+
266
+
267
+
268
  // Fungsi untuk mendapatkan URL audio MP3 dari video YouTube
269
  async function getAudioMP3Url(videoUrl) {
270
  try {
271
+ /*------------------
272
  const requestData = {"url":videoUrl,"vQuality":"360","filenamePattern":"pretty","isAudioOnly":"true"}
273
  const config = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36', 'Referer': 'https://cobalt.tools/' } };
274
+ */
275
+ let obj = { url: videoUrl }
276
+ const video = await fetchCobaltOnly(obj.url, { isAudioOnly: 'audio', vQuality: 'max' })
277
  const path_audio = path.join(tempDir, generateRandomName(10) + '.mp3');
278
  const id_video = await GetId(videoUrl);
279
  const infoVids = await getVideoDetailsWithApi(id_video);