𝐃𝐀𝐑𝐑𝐄𝐋𝐋 πŒπ”π‚π‡π„π‘πˆ ⚑ commited on
Commit
eb9a5cf
Β·
unverified Β·
1 Parent(s): 00d90e2

Create dl-xdown.js

Browse files
Files changed (1) hide show
  1. plugins/dl-xdown.js +76 -0
plugins/dl-xdown.js ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { cmd } = require('../command');
2
+ const axios = require('axios');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ // Simulated fetchJson function for API requests
7
+ const fetchJson = async (url) => {
8
+ try {
9
+ const response = await axios.get(url);
10
+ return response.data;
11
+ } catch (error) {
12
+ console.error(`fetchJson Error: ${error.message}`);
13
+ if (error.response) {
14
+ console.error(`Response Status: ${error.response.status}`);
15
+ console.error(`Response Data: ${JSON.stringify(error.response.data, null, 2)}`);
16
+ }
17
+ return null;
18
+ }
19
+ };
20
+
21
+ cmd({
22
+ pattern: "xdownload",
23
+ react: "πŸ“₯",
24
+ desc: "Download videos from Xvideos.",
25
+ category: "utility",
26
+ filename: __filename
27
+ }, async (conn, mek, m, { q, reply }) => {
28
+ try {
29
+ if (!q) return reply("❌ Please provide a valid Xvideos URL.");
30
+
31
+ const apiUrl = `https://api.giftedtech.web.id/api/download/xvideosdl?apikey=gifted&url=${encodeURIComponent(q)}`;
32
+ console.log("Requesting API with URL:", apiUrl);
33
+
34
+ // Fetch video data
35
+ const response = await fetchJson(apiUrl);
36
+ if (!response || !response.result) {
37
+ console.error("❌ Failed to fetch video. Please check the URL or try again later.");
38
+ return reply("❌ Failed to fetch video. Please check the URL or try again later.");
39
+ }
40
+
41
+ const videoData = response.result;
42
+ const videoUrl = videoData.download_url;
43
+ const videoTitle = videoData.title.replace(/[<>:"/\\|?*]/g, ''); // Clean the title for file naming
44
+ const videoPath = path.join(__dirname, `${videoTitle}.mp4`);
45
+
46
+ // Download the video
47
+ console.log("Subzero Downloading video...");
48
+ const videoResponse = await axios({
49
+ url: videoUrl,
50
+ method: 'GET',
51
+ responseType: 'stream',
52
+ });
53
+
54
+ // Save the video file locally
55
+ const writer = fs.createWriteStream(videoPath);
56
+ videoResponse.data.pipe(writer);
57
+
58
+ await new Promise((resolve, reject) => {
59
+ writer.on('finish', resolve);
60
+ writer.on('error', reject);
61
+ });
62
+
63
+ console.log(`Subzero downloaded video successfully: ${videoPath}`);
64
+
65
+ // Send the video to the user
66
+ await conn.sendMessage(m.chat, { video: fs.readFileSync(videoPath), caption: `πŸŽ₯ *Title:* ${videoData.title}\nπŸ‘€ *Views:* ${videoData.views}\nπŸ‘ *Likes:* ${videoData.likes}` });
67
+
68
+ // Clean up the downloaded file
69
+ fs.unlinkSync(videoPath);
70
+
71
+ console.log("Video sent and file cleaned up.");
72
+ } catch (error) {
73
+ console.error("Unexpected Error:", error.message);
74
+ return reply("❌ An error occurred while processing your request. Please try again.");
75
+ }
76
+ });