-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoutube.js
144 lines (107 loc) Β· 10.1 KB
/
youtube.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
const { zokou } = require("../framework/zokou");
const yts = require('yt-search');
const ytdl = require('ytdl-core');
const fs = require('fs');
const yt=require("../framework/dl/ytdl-core.js")
const ffmpeg = require("fluent-ffmpeg");
const yts1 = require("youtube-yts");
//var fs =require("fs-extra")
zokou({
nomCom: "play",
categorie: "Search",
reaction: "π§"
}, async (origineMessage, zk, commandeOptions) => {
const { ms, repondre, arg } = commandeOptions;
if (!arg[0]) {
repondre("wrong!!! Ie. _Play hozambe by Beltah ft shifura._");
return;
}
try {
let topo = arg.join(" ")
const search = await yts(topo);
const videos = search.videos;
if (videos && videos.length > 0 && videos[0]) {
const urlElement = videos[0].url;
let infoMess = {
image: {url : videos[0]. thumbnail},
caption : `\ANYWAY-MD\n\n*song name :* _${videos[0].title}_
*Time :* _${videos[0].timestamp}_
*Url :* _${videos[0].url}_
Β©ππ« *Anyway*`
}
zk.sendMessage(origineMessage,infoMess,{quoted:ms}) ;
// Obtenir le flux audio de la vidΓ©o
const audioStream = ytdl(urlElement, { filter: 'audioonly', quality: 'highestaudio' });
// Nom du fichier local pour sauvegarder le fichier audio
const filename = 'audio.mp3';
// Γcrire le flux audio dans un fichier local
const fileStream = fs.createWriteStream(filename);
audioStream.pipe(fileStream);
fileStream.on('finish', () => {
// Envoi du fichier audio en utilisant l'URL du fichier local
zk.sendMessage(origineMessage, { audio: { url:"audio.mp3"},mimetype:'audio/mp4' }, { quoted: ms,ptt: false });
console.log("Envoi du fichier audio terminΓ© !");
});
fileStream.on('error', (error) => {
console.error('Erreur lors de l\'Γ©criture du fichier audio :', error);
repondre('Une erreur est survenue lors de l\'Γ©criture du fichier audio.');
});
} else {
repondre('Aucune vidΓ©o trouvΓ©e.');
}
} catch (error) {
console.error('Erreur lors de la recherche ou du tΓ©lΓ©chargement de la vidΓ©o :', error);
repondre('Une erreur est survenue lors de la recherche ou du tΓ©lΓ©chargement de la vidΓ©o.');
}
});
zokou({
nomCom: "video",
categorie: "Search",
reaction: "π₯"
}, async (origineMessage, zk, commandeOptions) => {
const { arg, ms, repondre } = commandeOptions;
if (!arg[0]) {
repondre("insert video name Ie. _video hozambee by Beltah ft shifura._");
return;
}
const topo = arg.join(" ");
try {
const search = await yts(topo);
const videos = search.videos;
if (videos && videos.length > 0 && videos[0]) {
const Element = videos[0];
let InfoMess = {
image: { url: videos[0].thumbnail },
caption: `ANYWAY-MDβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n\n*Video name :* _${Element.title}_
*Time :* _${Element.timestamp}_
*Url :* _${Element.url}_
\n\n\n Β©ππ« *Anyway*`
};
zk.sendMessage(origineMessage, InfoMess, { quoted: ms });
// Obtenir les informations de la vidΓ©o Γ partir du lien YouTube
const videoInfo = await ytdl.getInfo(Element.url);
// Format vidΓ©o avec la meilleure qualitΓ© disponible
const format = ytdl.chooseFormat(videoInfo.formats, { quality: '18' });
// TΓ©lΓ©charger la vidΓ©o
const videoStream = ytdl.downloadFromInfo(videoInfo, { format });
// Nom du fichier local pour sauvegarder la vidΓ©o
const filename = 'video.mp4';
// Γcrire le flux vidΓ©o dans un fichier local
const fileStream = fs.createWriteStream(filename);
videoStream.pipe(fileStream);
fileStream.on('finish', () => {
// Envoi du fichier vidΓ©o en utilisant l'URL du fichier local
zk.sendMessage(origineMessage, { video: { url :"./video.mp4"} , caption: "Β©SUPER-MD", gifPlayback: false }, { quoted: ms });
});
fileStream.on('error', (error) => {
console.error('Erreur lors de l\'Γ©criture du fichier vidΓ©o :', error);
repondre('Une erreur est survenue lors de l\'Γ©criture du fichier vidΓ©o.');
});
} else {
repondre('No video found');
}
} catch (error) {
console.error('Erreur lors de la recherche ou du tΓ©lΓ©chargement de la vidΓ©o :', error);
repondre('Une erreur est survenue lors de la recherche ou du tΓ©lΓ©chargement de la vidΓ©o.');
}
});