forked from juma-tec/MALIK-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt-playlist.js
85 lines (79 loc) · 3.34 KB
/
yt-playlist.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
const { tlang, cmd, sleep, getBuffer, prefix, Config } = require('../lib')
const ytdl = require('ytdl-secktor')
const yts = require('secktor-pack')
const fs = require('fs')
var videotime = 60000 // 1000 min
var dlsize = 250 // 250mb
cmd({
pattern: "playlist",
desc: "Downloads video from playlist.",
category: "downloader",
filename: __filename,
use: '<yt playlist url>',
},
async(Void, citel, text) => {
const getRandom = (ext) => {
return `${Math.floor(Math.random() * 10000)}${ext}`;
};
if (!text) {
citel.reply(`❌Please provide me a url`);
return;
}
let urlYtt = text.split('=')[1]
console.log(urlYtt)
var opts = { listId: urlYtt }
yts( opts, async function ( err, playlist ) {
if ( err ) throw err
citel.reply('This Process will take a bit time.');
for (let i=0;i<playlist.videos.length;i++){
if(playlist.videos[i].videoId===undefined) continue
let urlYt = playlist.videos[i].videoId
try {
let infoYt = await ytdl.getInfo(urlYt);
if (infoYt.videoDetails.lengthSeconds >= videotime) continue
let titleYt = infoYt.videoDetails.title;
let randomName = getRandom(".mp4");
const stream = ytdl(urlYt, {
filter: (info) => info.itag == 22 || info.itag == 18,
})
.pipe(fs.createWriteStream(`./${randomName}`));
await new Promise((resolve, reject) => {
stream.on("error", reject);
stream.on("finish", resolve);
});
let stats = fs.statSync(`./${randomName}`);
let fileSizeInBytes = stats.size;
let fileSizeInMegabytes = fileSizeInBytes / (1024 * 1024);
if (fileSizeInMegabytes <= dlsize) {
let yts = require("secktor-pack");
let search = await yts(text);
let buttonMessage = {
video: fs.readFileSync(`./${randomName}`),
jpegThumbnail: log0,
mimetype: 'video/mp4',
fileName: `${titleYt}.mp4`,
caption: ` ⿻ Title : ${titleYt}\n ⿻ File Size : ${fileSizeInMegabytes} MB`,
headerType: 4,
contextInfo: {
externalAdReply: {
title: titleYt,
body: citel.pushName,
thumbnail: log0,
renderLargerThumbnail: true,
mediaType: 2,
mediaUrl: 'https://github.com/SamPandey001/Secktor-Md',
sourceUrl: 'https://github.com/SamPandey001/Secktor-Md'
}
}
}
Void.sendMessage(citel.chat, buttonMessage, { quoted: citel })
} else {
citel.reply(`❌ File size bigger than ${dlsize}mb.`);
}
fs.unlinkSync(`./${randomName}`);
} catch (e) {
console.log(e)
}
}})
}
)