Update app.js
Browse files
app.js
CHANGED
|
@@ -97,19 +97,43 @@ app.get('/ytdl', async (req, res) => {
|
|
| 97 |
if (!id) {
|
| 98 |
return res.status(400).send('Parameter "id" is required.');
|
| 99 |
}
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
try {
|
| 104 |
-
const
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
} catch (error) {
|
| 114 |
console.error(error);
|
| 115 |
res.status(500).send('Something went wrong while processing the request.');
|
|
|
|
| 97 |
if (!id) {
|
| 98 |
return res.status(400).send('Parameter "id" is required.');
|
| 99 |
}
|
| 100 |
+
|
| 101 |
+
try {
|
| 102 |
+
const response = await fetch(`https://api.allorigins.win/raw?url=https://ytdlp.online/stream?command=https://www.youtube.com/watch?v=${id} --get-url`, {
|
| 103 |
+
timeout: 1000,
|
| 104 |
+
cache: 'no-store'
|
| 105 |
+
});
|
| 106 |
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
| 107 |
+
const responseText = await response.text();
|
| 108 |
+
const urls = responseText.split('\n')
|
| 109 |
+
.filter(line => line.trim().startsWith('data:'))
|
| 110 |
+
.map(line => line.substring(5).trim())
|
| 111 |
+
.filter(url => url.startsWith('http'));
|
| 112 |
+
res.json({ urls });
|
| 113 |
+
} catch (error) {
|
| 114 |
+
console.error(error);
|
| 115 |
+
res.status(500).send('Something went wrong while processing the request.');
|
| 116 |
+
}
|
| 117 |
+
});
|
| 118 |
|
| 119 |
+
app.get('/ytdl/v1', async (req, res) => {
|
| 120 |
+
const id = req.query.id;
|
| 121 |
+
|
| 122 |
+
if (!id) {
|
| 123 |
+
return res.status(400).send('Parameter "id" is required.');
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
try {
|
| 127 |
+
const response = await fetch(`https://api.allorigins.win/raw?url=https://ytdlp.online/stream?command=https://www.youtube.com/watch?v=${id} -j`, {
|
| 128 |
+
timeout: 1000,
|
| 129 |
+
cache: 'no-store'
|
| 130 |
+
});
|
| 131 |
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
| 132 |
+
const responseText = await response.text();
|
| 133 |
+
const urls = responseText.split('\n')
|
| 134 |
+
.filter(line => line.trim().startsWith('data:'))
|
| 135 |
+
.map(line => line.substring(5).trim());
|
| 136 |
+
res.json(urls);
|
| 137 |
} catch (error) {
|
| 138 |
console.error(error);
|
| 139 |
res.status(500).send('Something went wrong while processing the request.');
|