-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
129 lines (109 loc) · 4.28 KB
/
Copy pathserver.js
File metadata and controls
129 lines (109 loc) · 4.28 KB
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
const express = require('express');
const axios = require('axios');
const { JSDOM } = require('jsdom');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get('/down', async (req, res) => {
try {
const videoUrl = req.query.url;
if (!videoUrl) {
return res.status(400).json({ error: 'URL parameter is required' });
}
const formData = new URLSearchParams();
formData.append('sf_url', videoUrl);
formData.append('new', '2');
formData.append('lang', 'en');
formData.append('app', '');
formData.append('country', 'bd');
formData.append('os', 'Android');
formData.append('browser', 'Chrome WebView');
formData.append('channel', 'main');
const response = await axios.post('https://en1.savefrom.net/savefrom.php', formData, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
},
timeout: 30000
});
const dom = new JSDOM(response.data);
const document = dom.window.document;
const result = {
success: true,
videoInfo: {},
downloadLinks: []
};
const titleElement = document.querySelector('.info-box .row.title');
if (titleElement) {
result.videoInfo.title = titleElement.textContent.trim();
}
const durationElement = document.querySelector('.info-box .row.duration');
if (durationElement) {
result.videoInfo.duration = durationElement.textContent.trim();
}
const downloadButtons = document.querySelectorAll('.link-download, .download-btn, .def-btn-name');
downloadButtons.forEach(button => {
const link = button.href || button.getAttribute('data-link');
const quality = button.textContent.trim();
if (link && link.startsWith('http')) {
result.downloadLinks.push({
quality: quality,
url: link,
direct: true
});
}
});
const hiddenLinks = document.querySelectorAll('.link-box .links a[href*="download"]');
hiddenLinks.forEach(link => {
if (link.href && link.href.startsWith('http')) {
result.downloadLinks.push({
quality: link.textContent.trim(),
url: link.href,
direct: true
});
}
});
if (result.downloadLinks.length === 0) {
const allLinks = document.querySelectorAll('a[href*="download"]');
allLinks.forEach(link => {
if (link.href && link.href.startsWith('http') && !link.href.includes('savefrom.net')) {
result.downloadLinks.push({
quality: link.textContent.trim() || 'Unknown Quality',
url: link.href,
direct: true
});
}
});
}
if (result.downloadLinks.length === 0) {
return res.status(404).json({
success: false,
error: 'No download links found',
rawHtml: response.data
});
}
res.json(result);
} catch (error) {
console.error('Error:', error.message);
res.status(500).json({
success: false,
error: 'Internal server error',
message: error.message
});
}
});
app.get('/', (req, res) => {
res.json({
message: 'Video Downloader API',
usage: 'GET /down?url=YOUR_VIDEO_URL',
example: 'GET /down?url=https://www.youtube.com/watch?v=VIDEO_ID',
supported: ['YouTube', 'Facebook', 'Instagram', 'Twitter', 'TikTok', 'Dailymotion', 'Vimeo', 'VK', 'SoundCloud', 'Reddit', 'Threads', 'Xiaohongshu']
});
});
app.use((req, res) => {
res.status(404).json({ error: 'Endpoint not found' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});