ilhamdev commited on
Commit
345b44b
·
verified ·
1 Parent(s): 9758b02

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +12 -15
index.js CHANGED
@@ -4,9 +4,7 @@ const express = require('express');
4
  const ytdl = require('ytdl-core');
5
  const { Writable, pipeline } = require('stream');
6
  const util = require('util');
7
- const FormData = require('form-data');
8
  const axios = require('axios');
9
- const FileType = require('file-type');
10
 
11
  // Regex untuk mengidentifikasi URL YouTube dan Mega
12
  const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/;
@@ -23,20 +21,19 @@ const post = async (url, form, headers = {}) => {
23
 
24
  //YTDL-CORE
25
  async function uploadBuffer(buffer) {
26
- //file: (binary)
27
- //expirationTime: 1
28
- let mime = await FileType.fromBuffer(buffer)
29
- let formData = new FormData()
30
- formData.append('file', buffer, `${Date.now()}.${mime.ext}`)
31
- formData.append('expirationTime', 1)
32
- let { data } = await axios.post(`https://cdn.itzpire.site/upload`, formData, {
33
  headers: {
34
- ...formData.getHeaders(),
35
- 'accept': 'application/json',
36
- 'Content-Type': 'multipart/form-data'
37
  }
 
 
 
 
 
 
38
  })
39
- return data?.fileUrl
40
  }
41
  async function streamToBuffer(stream) {
42
  const chunks = [];
@@ -105,9 +102,9 @@ async function ytmp4(url, quality = 'highestvideo') {
105
  try {
106
  const ID = ytdl.getVideoID(url),
107
  data = await ytdl.getInfo('https://www.youtube.com/watch?v=' + ID)
108
- /*const videoStream = await ytdl(ID, { quality: 'highestvideo' });
109
  let buffer = await streamToBuffer(videoStream)
110
- let upload = await uploadBuffer(buffer)*/
111
  let format = ytdl.chooseFormat(data.formats, { quality: quality });
112
 
113
  if (format) {
 
4
  const ytdl = require('ytdl-core');
5
  const { Writable, pipeline } = require('stream');
6
  const util = require('util');
 
7
  const axios = require('axios');
 
8
 
9
  // Regex untuk mengidentifikasi URL YouTube dan Mega
10
  const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/;
 
21
 
22
  //YTDL-CORE
23
  async function uploadBuffer(buffer) {
24
+ return new Promise(async (resolve, reject) => {
25
+ let res = await axios.post('https://ilhamdev-uploader.hf.space/upload', {
26
+ file: buffer.toString('base64'),
 
 
 
 
27
  headers: {
28
+ 'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
 
 
29
  }
30
+ }).catch(e => reject(e))
31
+ if (res.status !== 200) {
32
+ resolve(res?.statusText)
33
+ } else {
34
+ resolve(res?.data?.url)
35
+ }
36
  })
 
37
  }
38
  async function streamToBuffer(stream) {
39
  const chunks = [];
 
102
  try {
103
  const ID = ytdl.getVideoID(url),
104
  data = await ytdl.getInfo('https://www.youtube.com/watch?v=' + ID)
105
+ const videoStream = await ytdl(ID, { quality: 'highestvideo' });
106
  let buffer = await streamToBuffer(videoStream)
107
+ let upload = await uploadBuffer(buffer)
108
  let format = ytdl.chooseFormat(data.formats, { quality: quality });
109
 
110
  if (format) {