wudysoft commited on
Commit
86e6732
·
verified ·
1 Parent(s): 4a8acf9

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +35 -11
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
- const command = `https://www.youtube.com/watch?v=${id} -j`;
101
- const apiUrl = `https://api.allorigins.win/raw?url=https://ytdlp.online/stream?command=${encodeURIComponent(command)}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
 
 
 
 
 
 
 
103
  try {
104
- const browser = await chromium.launch({ headless: true });
105
- const context = await browser.newContext({
106
- userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36',
107
- });
108
- const page = await context.newPage();
109
- await page.goto(apiUrl);
110
- const rawText = await page.evaluate(() => document.body.innerText);
111
- await browser.close();
112
- res.send(rawText);
 
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.');