Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let axios = require('axios')
- function ytr(url) {
- let regEx = /^.*(youtu.be\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#\&\?]*).*/
- let id = url.match(regEx)
- return id[2]
- }
- function round(value, precision) {
- var multiplier = Math.pow(10, precision || 0)
- return Math.round(value * multiplier) / multiplier
- }
- var _1MB = 1024 * 1024
- var _1GB = 1024 * _1MB
- var _1TB = 1024 * _1GB
- function formatSize(size) {
- if (size < 1024) {
- return size + ' B'
- } else if (size < _1MB) {
- return round(size/1024, 1) + ' KB'
- } else if (size < _1GB) {
- return round(size/_1MB, 1) + ' MB'
- } else if (size < _1TB) {
- return round(size/_1GB, 1) + ' GB'
- } else {
- return round(size/_1TB, 1) + ' TB'
- } return ''
- }
- function extract(id) {
- return new Promise(async(resolve, reject) => {
- let json = await axios.get('https://api.btclod.com/v1/youtube/get-download-link/?file_id=' + id)
- resolve(json.data)
- })
- }
- function analyze(url) {
- return new Promise(async(resolve, reject) => {
- let json = await axios.get('https://api.btclod.com/v1/youtube/extract-infos/?detail=' + ytr(url) + '&video=1')
- if (json.data.code != 200) return resolve({ creator: '@neoxrs – Wildan Izzudin', status: false })
- let video = [], audio = []
- for (let i=0; i<json.data.data.videos.length; i++) {
- video.push({
- id: json.data.data.videos[i].id,
- type: json.data.data.videos[i].extension,
- quality: json.data.data.videos[i].format_note,
- bytes: json.data.data.videos[i].file_size,
- size: json.data.data.videos[i].file_size != '~' ? formatSize(json.data.data.videos[i].file_size) : '~'
- })
- }
- for (let i=0; i<json.data.data.audios.length; i++) {
- audio.push({
- id: json.data.data.audios[i].id,
- type: json.data.data.audios[i].extension,
- quality: json.data.data.audios[i].format_note,
- bytes: json.data.data.audios[i].file_size,
- size: json.data.data.audios[i].file_size != '~' ? formatSize(json.data.data.audios[i].file_size) : '~'
- })
- } resolve({ creator: '@neoxrs – Wildan Izzudin', status: true, data: [ ...video, ...audio ] })
- })
- }
- // USAGE FUNCTION
- // analyze('https://youtu.be/j5-yKhDd64s').then(res => console.log(res))
- // extract('ajUteUtoRGQ2NHM6dmlkZW86Mzk4KzE0MDo3MjBwOm1wNA==').then(res => console.log(res))
Add Comment
Please, Sign In to add comment