forked from DARKCRIME1/xmas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYtdl.js
187 lines (152 loc) · 8.41 KB
/
Ytdl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
const Trex = require('../events');
const {MessageType,Mimetype} = require('@adiwajshing/baileys');
const translatte = require('translatte');
const config = require('../config');
const axios = require('axios')
const { errorMessage, infoMessage } = require('../helpers');
//============================== CURRENCY =============================================
const { exchangeRates } = require('exchange-rates-api');
const ExchangeRatesError = require('exchange-rates-api/src/exchange-rates-error.js')
//============================== TTS ==================================================
const fs = require('fs');
const https = require('https');
const googleTTS = require('google-translate-tts');
//=====================================================================================
//============================== YOUTUBE ==============================================
const ytdl = require('ytdl-core');
const ffmpeg = require('fluent-ffmpeg');
const yts = require( 'yt-search' )
const got = require("got");
const ID3Writer = require('browser-id3-writer');
const SpotifyWebApi = require('spotify-web-api-node');
const spotifyApi = new SpotifyWebApi({
clientId: 'acc6302297e040aeb6e4ac1fbdfd62c3',
clientSecret: '0e8439a1280a43aba9a5bc0a16f3f009'
});
//=====================================================================================
const Language = require('../language');
const Lang = Language.getString('scrapers');
const Glang = Language.getString('github');
const TKlang = Language.getString('tiktok');
const wiki = require('wikijs').default;
var gis = require('g-i-s');
if (config.WORKTYPE == 'public') {
Trex.addrex({pattern: 'play ?(.*)', fromMe: true, desc: Lang.PLAY_DESC}, (async (message, match) => {
if (match[1] === '') return await message.client.sendMessage(message.jid,'NEED WORD 🍁',MessageType.text);
let arama = await yts(match[1]);
arama = arama.all;
if(arama.length < 1) return await message.client.sendMessage(message.jid,Lang.NO_RESULT,MessageType.text);
var reply = await message.client.sendMessage(message.jid,`╭──────•◈•──────╮
sᴇᴀʀᴄʜɪɴɢ ʏᴏᴜʀ ꜱᴏɴɢ♪
▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄
━━━━━ •♬• ━━━━━
╰──────•◈•──────╯
﹏﹏﹏﹏﹏✪✭✪﹏﹏﹏﹏﹏
『T Rex Whatsapp Bot』`,MessageType.text);
let title = arama[0].title.replace(' ', '+');
let stream = ytdl(arama[0].videoId, {
quality: 'highestaudio',
});
got.stream(arama[0].image).pipe(fs.createWriteStream(title + '.jpg'));
ffmpeg(stream)
.audioBitrate(320)
.save('./' + title + '.mp3')
.on('end', async () => {
const writer = new ID3Writer(fs.readFileSync('./' + title + '.mp3'));
writer.setFrame('TIT2', arama[0].title)
.setFrame('TPE1', [arama[0].author.name])
.setFrame('APIC', {
type: 3,
data: fs.readFileSync(title + '.jpg'),
description: arama[0].description
});
writer.addTag();
reply = await message.client.sendMessage(message.jid,fs.readFileSync('./' + title + '.jpg'), MessageType.image, { caption: '\n```Song Name :\n'+ title +' ```\n\n'+`╭──────•◈•──────╮
ᴜᴘʟᴏᴀᴅɪɴɢ ʏᴏᴜʀ ꜱᴏɴɢ♫
ılı.lıllılı.ıllı.ılı.lıllılı.ıllı.
━━━━━ •♬• ━━━━━
╰──────•◈•──────╯
﹏﹏﹏﹏﹏✪✭✪﹏﹏﹏﹏﹏
『T Rex Whatsapp Bot』`+'\n' });
await message.client.sendMessage(message.jid,Buffer.from(writer.arrayBuffer), MessageType.document, {filename: title + '.mp3', mimetype: 'audio/mpeg', contextInfo: { forwardingScore: 1, isForwarded: false }});
});
}));
Trex.addrex({pattern: 'song ?(.*)', fromMe: true, desc: Lang.SONG_DESC}, (async (message, match) => {
if (match[1] === '') return await message.client.sendMessage(message.jid,Lang.NEED_TEXT_SONG,MessageType.text);
let arama = await yts(match[1]);
arama = arama.all;
if(arama.length < 1) return await message.client.sendMessage(message.jid,Lang.NO_RESULT,MessageType.text);
var reply = await message.client.sendMessage(message.jid,config.SD ,MessageType.text);
let title = arama[0].title.replace(' ', '+');
let stream = ytdl(arama[0].videoId, {
quality: 'highestaudio',
});
got.stream(arama[0].image).pipe(fs.createWriteStream(title + '.jpg'));
ffmpeg(stream)
.audioBitrate(320)
.save('./' + title + '.mp3')
.on('end', async () => {
const writer = new ID3Writer(fs.readFileSync('./' + title + '.mp3'));
writer.setFrame('TIT2', arama[0].title)
.setFrame('TPE1', [arama[0].author.name])
.setFrame('APIC', {
type: 3,
data: fs.readFileSync(title + '.jpg'),
description: arama[0].description
});
writer.addTag();
reply = await message.client.sendMessage(message.jid,config.SU ,MessageType.text);
await message.client.sendMessage(message.jid,Buffer.from(writer.arrayBuffer), MessageType.audio, {mimetype: Mimetype.mp4Audio, quoted: message.data, ptt: false});
});
}));
Trex.addrex({pattern: 'fsong ?(.*)', fromMe: true, desc: Lang.SONG_DESC}, (async (message, match) => {
if (match[1] === '') return await message.client.sendMessage(message.jid,Lang.NEED_TEXT_SONG,MessageType.text , {quoted: message.data});
let arama = await yts(match[1]);
arama = arama.all;
if(arama.length < 1) return await message.client.sendMessage(message.jid,Lang.NO_RESULT,MessageType.text);
var reply = await message.client.sendMessage(message.jid,config.SD,MessageType.text);
let title = arama[0].title.replace(' ', '+');
let stream = ytdl(arama[0].videoId, {
quality: 'highestaudio',
});
got.stream(arama[0].image).pipe(fs.createWriteStream(title + '.jpg'));
ffmpeg(stream)
.audioBitrate(320)
.save('./' + title + '.mp3')
.on('end', async () => {
const writer = new ID3Writer(fs.readFileSync('./' + title + '.mp3'));
writer.setFrame('TIT2', arama[0].title)
.setFrame('TPE1', [arama[0].author.name])
.setFrame('APIC', {
type: 3,
data: fs.readFileSync(title + '.jpg'),
description: arama[0].description
});
writer.addTag();
reply = await message.client.sendMessage(message.jid,config.SU,MessageType.text);
await message.client.sendMessage(message.jid,Buffer.from(writer.arrayBuffer), MessageType.document, {filename: title + '.mp3', mimetype: 'audio/mpeg'});
});
}));
Trex.addrex({pattern: 'video ?(.*)', fromMe: true, desc: 'hu'}, (async (message, match) => {
if (match[1] === '') return await message.client.sendMessage(message.jid,Lang.NEED_VIDEO,MessageType.text);
var VID = '';
try {
if (match[1].includes('watch')) {
var tsts = match[1].replace('watch?v=', '')
var alal = tsts.split('/')[3]
VID = alal
} else {
VID = match[1].split('/')[3]
}
} catch {
return await message.client.sendMessage(message.jid,Lang.NO_RESULT,MessageType.text);
}
var reply = await message.client.sendMessage(message.jid,config.VD,MessageType.text);
var yt = ytdl(VID, {filter: format => format.container === 'mp4' && ['720p', '480p', '360p', '240p', '144p'].map(() => true)});
yt.pipe(fs.createWriteStream('./' + VID + '.mp4'));
yt.on('end', async () => {
reply = await message.client.sendMessage(message.jid,config.VU,MessageType.text);
await message.client.sendMessage(message.jid,fs.readFileSync('./' + VID + '.mp4'), MessageType.video, {mimetype: Mimetype.mp4});
});
}));
}