HerzaJ commited on
Commit
c70caa4
·
verified ·
1 Parent(s): 9fc16f1

Update plugins/sora2.js

Browse files
Files changed (1) hide show
  1. plugins/sora2.js +37 -38
plugins/sora2.js CHANGED
@@ -39,24 +39,23 @@ async function proxyRequest(path, options = {}) {
39
  const proxyAgent = new HttpsProxyAgent(PROXY_URL);
40
 
41
  const headers = {
42
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
43
  'Accept': 'application/json, text/plain, */*',
44
  'Accept-Language': 'en-US,en;q=0.9',
45
  'X-Forwarded-For': fakeIP,
46
  'X-Real-IP': fakeIP,
47
- 'X-Client-IP': fakeIP,
48
  'Origin': 'https://bylo.ai',
49
  'Referer': 'https://bylo.ai/',
50
  ...(options.headers || {})
51
  };
52
 
53
- await randomDelay(500, 1500);
54
 
55
  const axiosConfig = {
56
  url: fullUrl,
57
  method: options.method || 'GET',
58
  headers: headers,
59
- timeout: 25000,
60
  httpAgent: proxyAgent,
61
  httpsAgent: proxyAgent,
62
  proxy: false,
@@ -73,60 +72,62 @@ async function proxyRequest(path, options = {}) {
73
 
74
  for (let attempt = 1; attempt <= 3; attempt++) {
75
  try {
76
- console.log(`Attempt ${attempt}: ${fullUrl}`);
77
 
78
  const response = await axios(axiosConfig);
79
 
80
- console.log(`Attempt ${attempt} got status ${response.status}`);
81
- console.log(`Response data:`, JSON.stringify(response.data).substring(0, 200));
82
 
83
  if (response.status === 403) {
84
- console.log('Got 403, waiting longer before retry...');
85
  await randomDelay(3000, 5000);
86
- throw new Error('API Bylo returned 403 Forbidden - possible rate limit or IP block');
87
  }
88
 
89
  if (response.status === 429) {
90
- console.log('Got 429 Too Many Requests, waiting...');
91
- await randomDelay(5000, 10000);
92
  if (attempt < 3) continue;
93
  throw new Error('Rate limit exceeded');
94
  }
95
 
96
  if (response.status >= 200 && response.status < 300) {
97
  if (!response.data) {
98
- throw new Error('Empty response from proxy');
99
  }
100
  return response;
101
  }
102
 
103
  if (response.status >= 400) {
104
- const errorMsg = response.data?.msg || response.data?.message || response.data?.error || 'Unknown error';
105
  throw new Error(`API error (${response.status}): ${errorMsg}`);
106
  }
107
 
108
  if (attempt < 3) {
109
- await randomDelay(2000, 4000);
110
  }
111
 
112
  } catch (error) {
113
  lastError = error;
114
- console.error(`Attempt ${attempt} failed:`, error.message);
 
 
 
 
115
 
116
  if (error.response) {
117
  console.error(`Response status: ${error.response.status}`);
118
- console.error(`Response data:`, error.response.data);
119
  }
120
 
121
  if (attempt < 3) {
122
- const waitTime = 3000 * attempt;
123
- console.log(`Retrying in ${waitTime/1000} seconds...`);
124
- await randomDelay(waitTime, waitTime + 2000);
125
  }
126
  }
127
  }
128
 
129
- throw new Error(`Proxy request failed after 3 attempts: ${lastError?.message || 'Unknown error'}`);
130
  }
131
 
132
  async function createTempEmail() {
@@ -141,7 +142,7 @@ async function createTempEmail() {
141
  'Application-Version': '4.0.0',
142
  'X-CORS-Header': 'iaWg3pchvFx48fY'
143
  },
144
- timeout: 15000
145
  });
146
 
147
  console.log(`Email created: ${data.email}`);
@@ -153,7 +154,7 @@ async function getHcaptchaToken() {
153
  const { data } = await axios.get(
154
  'https://anabot.my.id/api/tools/bypass?url=https%3A%2F%2Fapi.hcaptcha.com&siteKey=6f70c0f2-3ef6-4972-9fb6-c0b4bade3af8&type=hcaptcha-invisible&apikey=freeApikey',
155
  {
156
- timeout: 15000
157
  }
158
  );
159
 
@@ -168,12 +169,12 @@ async function getHcaptchaToken() {
168
  async function sendVerificationEmail(email) {
169
  console.log(`Sending verification email to ${email}...`);
170
 
171
- await randomDelay(1000, 2000);
172
 
173
  const hcaptchaToken = await getHcaptchaToken();
174
  const encodedEmail = encodeURIComponent(email);
175
 
176
- await randomDelay(500, 1000);
177
 
178
  const { data } = await proxyRequest(
179
  `/api/auth/send-captcha?email=${encodedEmail}&type=register`,
@@ -192,18 +193,18 @@ async function sendVerificationEmail(email) {
192
  }
193
 
194
  console.log('Verification email sent successfully');
195
- await randomDelay(3000, 5000);
196
  return true;
197
  }
198
 
199
  async function getVerificationCode(email) {
200
  console.log('Waiting for verification code...');
201
  let attempts = 0;
202
- const maxAttempts = 30;
203
 
204
  while (attempts < maxAttempts) {
205
  try {
206
- await new Promise(resolve => setTimeout(resolve, 5000));
207
 
208
  const { data } = await axios.get(
209
  `https://api.internal.temp-mail.io/api/v3/email/${email}/messages`,
@@ -214,7 +215,7 @@ async function getVerificationCode(email) {
214
  'Application-Version': '4.0.0',
215
  'X-CORS-Header': 'iaWg3pchvFx48fY'
216
  },
217
- timeout: 10000
218
  }
219
  );
220
 
@@ -229,14 +230,14 @@ async function getVerificationCode(email) {
229
  }
230
 
231
  attempts++;
232
- console.log(`Checking for verification code... attempt ${attempts}/${maxAttempts}`);
233
  } catch (error) {
234
- console.log(`Email check attempt ${attempts} failed:`, error.message);
235
  attempts++;
236
  }
237
  }
238
 
239
- throw new Error('Verification code not received after 30 attempts');
240
  }
241
 
242
  async function registerAccount(email, password, verificationCode) {
@@ -262,8 +263,6 @@ async function registerAccount(email, password, verificationCode) {
262
  }
263
 
264
  console.log('Account registered successfully');
265
- console.log(`Email: ${email}`);
266
- console.log(`Password: ${password}`);
267
 
268
  return {
269
  token: data.data.token,
@@ -274,7 +273,7 @@ async function registerAccount(email, password, verificationCode) {
274
 
275
  async function createVideoTask(prompt, ratio, authToken, email) {
276
  console.log('Creating video task...');
277
- await randomDelay(2000, 3000);
278
 
279
  const { data } = await proxyRequest('/aimodels/api/v1/ai/video/create', {
280
  method: 'POST',
@@ -335,14 +334,14 @@ async function getTaskStatus(taskId, authToken) {
335
  async function waitForVideoCompletion(taskId, authToken) {
336
  console.log('Waiting for video generation...');
337
  let attempts = 0;
338
- const maxAttempts = 120;
339
 
340
  while (attempts < maxAttempts) {
341
- await randomDelay(5000, 7000);
342
 
343
  const taskData = await getTaskStatus(taskId, authToken);
344
 
345
- console.log(`Video status check ${attempts + 1}/${maxAttempts} - State: ${taskData.state}`);
346
 
347
  if (taskData.state === 1 && taskData.completeData) {
348
  const completeData = JSON.parse(taskData.completeData);
@@ -357,7 +356,7 @@ async function waitForVideoCompletion(taskId, authToken) {
357
  attempts++;
358
  }
359
 
360
- throw new Error('Video generation timeout after 10 minutes');
361
  }
362
 
363
  async function sora2(prompt, ratio = 'portrait') {
 
39
  const proxyAgent = new HttpsProxyAgent(PROXY_URL);
40
 
41
  const headers = {
42
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
43
  'Accept': 'application/json, text/plain, */*',
44
  'Accept-Language': 'en-US,en;q=0.9',
45
  'X-Forwarded-For': fakeIP,
46
  'X-Real-IP': fakeIP,
 
47
  'Origin': 'https://bylo.ai',
48
  'Referer': 'https://bylo.ai/',
49
  ...(options.headers || {})
50
  };
51
 
52
+ await randomDelay(300, 800);
53
 
54
  const axiosConfig = {
55
  url: fullUrl,
56
  method: options.method || 'GET',
57
  headers: headers,
58
+ timeout: 60000,
59
  httpAgent: proxyAgent,
60
  httpsAgent: proxyAgent,
61
  proxy: false,
 
72
 
73
  for (let attempt = 1; attempt <= 3; attempt++) {
74
  try {
75
+ console.log(`[${new Date().toISOString()}] Attempt ${attempt}: ${fullUrl}`);
76
 
77
  const response = await axios(axiosConfig);
78
 
79
+ console.log(`[${new Date().toISOString()}] Status ${response.status}`);
 
80
 
81
  if (response.status === 403) {
82
+ console.log('Got 403, waiting...');
83
  await randomDelay(3000, 5000);
84
+ throw new Error('403 Forbidden');
85
  }
86
 
87
  if (response.status === 429) {
88
+ console.log('Got 429, waiting...');
89
+ await randomDelay(5000, 8000);
90
  if (attempt < 3) continue;
91
  throw new Error('Rate limit exceeded');
92
  }
93
 
94
  if (response.status >= 200 && response.status < 300) {
95
  if (!response.data) {
96
+ throw new Error('Empty response');
97
  }
98
  return response;
99
  }
100
 
101
  if (response.status >= 400) {
102
+ const errorMsg = response.data?.msg || response.data?.message || 'Unknown error';
103
  throw new Error(`API error (${response.status}): ${errorMsg}`);
104
  }
105
 
106
  if (attempt < 3) {
107
+ await randomDelay(2000, 3000);
108
  }
109
 
110
  } catch (error) {
111
  lastError = error;
112
+ console.error(`[${new Date().toISOString()}] Attempt ${attempt} failed:`, error.message);
113
+
114
+ if (error.code === 'ECONNABORTED' || error.message.includes('timeout')) {
115
+ console.error('Timeout error detected');
116
+ }
117
 
118
  if (error.response) {
119
  console.error(`Response status: ${error.response.status}`);
 
120
  }
121
 
122
  if (attempt < 3) {
123
+ const waitTime = 2000 * attempt;
124
+ console.log(`Retrying in ${waitTime/1000}s...`);
125
+ await randomDelay(waitTime, waitTime + 1000);
126
  }
127
  }
128
  }
129
 
130
+ throw new Error(`Proxy request failed: ${lastError?.message || 'Unknown error'}`);
131
  }
132
 
133
  async function createTempEmail() {
 
142
  'Application-Version': '4.0.0',
143
  'X-CORS-Header': 'iaWg3pchvFx48fY'
144
  },
145
+ timeout: 20000
146
  });
147
 
148
  console.log(`Email created: ${data.email}`);
 
154
  const { data } = await axios.get(
155
  'https://anabot.my.id/api/tools/bypass?url=https%3A%2F%2Fapi.hcaptcha.com&siteKey=6f70c0f2-3ef6-4972-9fb6-c0b4bade3af8&type=hcaptcha-invisible&apikey=freeApikey',
156
  {
157
+ timeout: 30000
158
  }
159
  );
160
 
 
169
  async function sendVerificationEmail(email) {
170
  console.log(`Sending verification email to ${email}...`);
171
 
172
+ await randomDelay(500, 1000);
173
 
174
  const hcaptchaToken = await getHcaptchaToken();
175
  const encodedEmail = encodeURIComponent(email);
176
 
177
+ await randomDelay(300, 700);
178
 
179
  const { data } = await proxyRequest(
180
  `/api/auth/send-captcha?email=${encodedEmail}&type=register`,
 
193
  }
194
 
195
  console.log('Verification email sent successfully');
196
+ await randomDelay(2000, 3000);
197
  return true;
198
  }
199
 
200
  async function getVerificationCode(email) {
201
  console.log('Waiting for verification code...');
202
  let attempts = 0;
203
+ const maxAttempts = 25;
204
 
205
  while (attempts < maxAttempts) {
206
  try {
207
+ await new Promise(resolve => setTimeout(resolve, 4000));
208
 
209
  const { data } = await axios.get(
210
  `https://api.internal.temp-mail.io/api/v3/email/${email}/messages`,
 
215
  'Application-Version': '4.0.0',
216
  'X-CORS-Header': 'iaWg3pchvFx48fY'
217
  },
218
+ timeout: 15000
219
  }
220
  );
221
 
 
230
  }
231
 
232
  attempts++;
233
+ console.log(`Checking code... ${attempts}/${maxAttempts}`);
234
  } catch (error) {
235
+ console.log(`Email check failed:`, error.message);
236
  attempts++;
237
  }
238
  }
239
 
240
+ throw new Error('Verification code not received');
241
  }
242
 
243
  async function registerAccount(email, password, verificationCode) {
 
263
  }
264
 
265
  console.log('Account registered successfully');
 
 
266
 
267
  return {
268
  token: data.data.token,
 
273
 
274
  async function createVideoTask(prompt, ratio, authToken, email) {
275
  console.log('Creating video task...');
276
+ await randomDelay(1000, 2000);
277
 
278
  const { data } = await proxyRequest('/aimodels/api/v1/ai/video/create', {
279
  method: 'POST',
 
334
  async function waitForVideoCompletion(taskId, authToken) {
335
  console.log('Waiting for video generation...');
336
  let attempts = 0;
337
+ const maxAttempts = 100;
338
 
339
  while (attempts < maxAttempts) {
340
+ await randomDelay(4000, 6000);
341
 
342
  const taskData = await getTaskStatus(taskId, authToken);
343
 
344
+ console.log(`Status check ${attempts + 1}/${maxAttempts} - State: ${taskData.state}`);
345
 
346
  if (taskData.state === 1 && taskData.completeData) {
347
  const completeData = JSON.parse(taskData.completeData);
 
356
  attempts++;
357
  }
358
 
359
+ throw new Error('Video generation timeout');
360
  }
361
 
362
  async function sora2(prompt, ratio = 'portrait') {