Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- - name: Yt Downloader
- - author: ibnusyawall
- - challange by: Bilal
- - require: node [needle, superagent, html-to-json, readline, colors, ora]
- - install: wget https://pastebin.com/raw/Y7m1JMpv -O ytdl.js
- */
- const needle = require('needle')
- const ora = require('ora')
- const fs = require('fs')
- const superagent = require('superagent')
- const html2json = require('html-to-json')
- const readline = require('readline')
- const spinner = ora('[+] Downloading ... ')
- require('colors')
- spinner.color = 'yellow'
- const ask = readline.createInterface({
- input : process.stdin,
- output: process.stdout
- })
- const log = console.log
- log('\n['.green, ' YTdL by Ibnusyawall ', ']'.green)
- log(' Black Coder Crush ')
- const config = {
- _url: `https://stafaband-76.com/grab/search/`
- }
- const _getId = (link, callback) => {
- superagent.post('https://mate12.y2mate.com/mp3/ajax').send({
- url: link,
- ajax: '1',
- }).set('content-type', 'application/x-www-form-urlencoded; charset=UTF-8').end((err, res) => {
- if (err) throw err;
- const data = JSON.parse(res.text)
- const html = data.result
- const _id_ = html.indexOf('_id:')
- const _vid = html.indexOf('v_id:')
- const __id = html.slice(_id_, _id_+31).split(' ')[1]
- const __vid= html.slice(_vid, _vid+19).split(' ')[1]
- callback(undefined, {
- id: __id.replace(/[\']/gi, ""),
- vid: __vid.replace(/[\']/gi, "")
- })
- })
- }
- const _getLink = (_link, callback) => {
- _getId(_link, (error, {id, vid} = {}) => {
- superagent.post('https://mate06.y2mate.com/mp3Convert').send({
- type: 'youtube',
- _id: `${id}`,
- v_id: `${vid}`,
- mp3_type: '128'
- }).set('content-type', 'application/x-www-form-urlencoded; charset=UTF-8').end((err, res) => {
- if (err) throw err;
- const data = JSON.parse(res.text)
- const html = data.result
- html2json.parse(`${html}`, {
- 'link': ['a', (alink) => {
- return alink.attr('href')
- }]
- }, (err, result) => {
- if (err) throw err
- callback(undefined, {
- link: result['link']['0']
- })
- })
- })
- })
- }
- ask.question('\n[?] Query: ', (q) => {
- if (q == '') {
- log('[!] Harap masukan query.'); process.exit()
- } else {
- superagent.get(`${config._url}${q}`).end((err, res) => {
- if (err) throw err
- let i = 0
- const json = [... res['body']]
- log('\n[+] Total: ', json.length, '\n')
- let jd = new Array()
- json.forEach(({title}) => {
- log(`[${i++}]`, title)
- return jd.push(title)
- })
- const _cari = (_title, callback) => {
- const _dt = json.find((obj) => {
- return obj.title === _title
- })
- callback(undefined, {
- _dtch: _dt
- })
- }
- ask.question(`\n[?] choice [0-${json.length-1}]: `, (_ch) => {
- if (_ch >= json.length-1) {
- log('\n[!] Tidak ditemukan nomor', _ch)
- } else {
- _cari(jd[`${_ch}`], (error, {_dtch} = {}) => {
- log('\njudul :', _dtch['title'])
- log('durasi:', _dtch['videoTime'])
- _getLink(`https://youtu.be/${_dtch['id']}`, (error, {link} = {}) => {
- spinner.start()
- const output = fs.createWriteStream(`./ostch | ${_dtch['title']}.mp3`)
- needle.get(link).pipe(output).on('finish', () => {
- spinner.text = 'Selesai.'
- spinner.succeed(`Berhasil didownload: ${_dtch['title']}`)
- })
- })
- })
- }
- })
- })
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement