JAYNESTV commited on
Commit
aad16e6
Β·
verified Β·
1 Parent(s): 1efdb9d

Upload 9 files

Browse files
Files changed (3) hide show
  1. all.php +38 -50
  2. index.php +0 -1
  3. kraudius_core.php +71 -24
all.php CHANGED
@@ -1,8 +1,13 @@
1
  <?php
2
  /**
3
- * all.php β€” JAYNES MAX TV (v3.3-direct)
4
- * Inaita runBatch() moja kwa moja bila HTTP curl kwa part files.
5
- * Hii inaepuka tatizo la timeout la v3.2-split.
 
 
 
 
 
6
  */
7
 
8
  header('Content-Type: application/json; charset=UTF-8');
@@ -13,67 +18,51 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(204); exit; }
13
  @ini_set('display_errors', '0');
14
  error_reporting(E_ERROR);
15
 
 
 
16
  ignore_user_abort(true);
17
- set_time_limit(300);
18
 
19
  require __DIR__ . '/kraudius_core.php';
20
 
21
- $t0 = microtime(true);
22
  $source = trim($_GET['source'] ?? 'kraudius');
23
 
24
- // Batches β€” zana 5 za parallel (simulated sequential)
25
- $batches = [
26
- [1, 11],
27
- [12, 22],
28
- [23, 30],
29
- [31, 40],
30
- [41, 52],
31
  ];
32
 
33
- $channels = [];
34
- $okCount = 0;
35
- $failCount = 0;
36
- $fb1Count = 0;
37
- $dupCount = 0;
38
- $partsDebug = [];
39
- $partsFailed = [];
40
 
41
- foreach ($batches as $idx => [$from, $to]) {
42
- $partName = 'part' . ($idx + 1) . '.php';
43
- $tPart = microtime(true);
44
 
45
- try {
46
- // Ita runBatch() moja kwa moja β€” bila HTTP
47
- $result = runBatch($from, $to, $source);
 
 
48
 
49
- $channels = array_merge($channels, $result['channels'] ?? []);
50
- $okCount += $result['ok_count'] ?? 0;
51
- $failCount += $result['fail_count'] ?? 0;
52
- $fb1Count += $result['with_fallback1'] ?? 0;
53
- $dupCount += $result['same_url_count'] ?? 0;
54
-
55
- $partsDebug[$partName] = [
56
- 'ok' => true,
57
- 'range' => "$from-$to",
58
- 'part_ms' => (int)((microtime(true) - $tPart) * 1000),
59
- 'elapsed_ms' => $result['elapsed_ms'] ?? null,
60
- ];
61
- } catch (Throwable $e) {
62
- $partsFailed[] = $partName;
63
- $partsDebug[$partName] = [
64
- 'ok' => false,
65
- 'range' => "$from-$to",
66
- 'ms' => (int)((microtime(true) - $tPart) * 1000),
67
- 'error' => $e->getMessage(),
68
- ];
69
- }
70
  }
71
 
72
  usort($channels, fn($a, $b) => ($a['channel'] ?? 0) <=> ($b['channel'] ?? 0));
73
 
74
  echo json_encode([
75
- 'success' => empty($partsFailed),
76
- 'version' => 'v3.3-direct',
77
  'source' => $source === 'all' ? 'KraudiusTV + LiveBlog365' : sourceLabel($source),
78
  'range' => '1-52',
79
  'total' => count($channels),
@@ -81,9 +70,8 @@ echo json_encode([
81
  'fail_count' => $failCount,
82
  'with_fallback1' => $fb1Count,
83
  'same_url_count' => $dupCount,
84
- 'parts_failed' => $partsFailed,
85
  'fetched_at' => date('Y-m-d H:i:s'),
86
  'elapsed_ms' => (int)((microtime(true) - $t0) * 1000),
87
  'parts_debug' => $partsDebug,
88
  'channels' => $channels,
89
- ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
 
1
  <?php
2
  /**
3
+ * all.php β€” JAYNES MAX TV (v3.2-split, in-process)
4
+ * Awali iliita part1.php...part5.php kupitia curl (self-HTTP), lakini
5
+ * baadhi ya hosting (mf. Hugging Face Spaces) zinaelekeza (301) hizo
6
+ * self-requests kwenye proxy ambayo haziitiki vizuri -> timeout.
7
+ *
8
+ * Sasa: inaita runBatch() MOJA KWA MOJA (function call ya ndani ya
9
+ * process hiihii), bila HTTP yoyote ya ndani. Haraka zaidi, salama
10
+ * kwa hosting yoyote.
11
  */
12
 
13
  header('Content-Type: application/json; charset=UTF-8');
 
18
  @ini_set('display_errors', '0');
19
  error_reporting(E_ERROR);
20
 
21
+ while (ob_get_level() > 0) { ob_end_flush(); }
22
+ ob_implicit_flush(true);
23
  ignore_user_abort(true);
 
24
 
25
  require __DIR__ . '/kraudius_core.php';
26
 
 
27
  $source = trim($_GET['source'] ?? 'kraudius');
28
 
29
+ // Ranges zilezile za part1..part5 (kwa taarifa/debug tu)
30
+ $ranges = [
31
+ 'part1' => [1, 11],
32
+ 'part2' => [12, 22],
33
+ 'part3' => [23, 33],
34
+ 'part4' => [34, 44],
35
+ 'part5' => [45, 52],
36
  ];
37
 
38
+ $t0 = microtime(true);
39
+ $channels = [];
40
+ $okCount = 0;
41
+ $failCount = 0;
42
+ $fb1Count = 0;
43
+ $dupCount = 0;
44
+ $partsDebug = [];
45
 
46
+ foreach ($ranges as $label => [$from, $to]) {
47
+ $result = runBatch($from, $to, $source);
 
48
 
49
+ $channels = array_merge($channels, $result['channels'] ?? []);
50
+ $okCount += $result['ok_count'] ?? 0;
51
+ $failCount += $result['fail_count'] ?? 0;
52
+ $fb1Count += $result['with_fallback1'] ?? 0;
53
+ $dupCount += $result['same_url_count'] ?? 0;
54
 
55
+ $partsDebug[$label] = [
56
+ 'range' => $result['range'] ?? "$from-$to",
57
+ 'elapsed_ms' => $result['elapsed_ms'] ?? null,
58
+ ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
  usort($channels, fn($a, $b) => ($a['channel'] ?? 0) <=> ($b['channel'] ?? 0));
62
 
63
  echo json_encode([
64
+ 'success' => true,
65
+ 'version' => 'v3.2-split-inprocess',
66
  'source' => $source === 'all' ? 'KraudiusTV + LiveBlog365' : sourceLabel($source),
67
  'range' => '1-52',
68
  'total' => count($channels),
 
70
  'fail_count' => $failCount,
71
  'with_fallback1' => $fb1Count,
72
  'same_url_count' => $dupCount,
 
73
  'fetched_at' => date('Y-m-d H:i:s'),
74
  'elapsed_ms' => (int)((microtime(true) - $t0) * 1000),
75
  'parts_debug' => $partsDebug,
76
  'channels' => $channels,
77
+ ], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
index.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
- // Ukurasa wa msingi β€” kuthibitisha backend inafanya kazi
3
  header('Content-Type: application/json; charset=UTF-8');
4
  echo json_encode([
5
  'ok' => true,
 
1
  <?php
 
2
  header('Content-Type: application/json; charset=UTF-8');
3
  echo json_encode([
4
  'ok' => true,
kraudius_core.php CHANGED
@@ -209,34 +209,81 @@ function detectType(string $url): string {
209
  // HTTP FETCH
210
  // ═══════════════════════════════════════════════════════════
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  function fetchPage(string $url): array {
213
  $cookieFile = sys_get_temp_dir() . '/jkr_' . md5($url) . '.txt';
214
  $parsed = parse_url($url);
215
  $host = ($parsed['scheme'] ?? 'https') . '://' . ($parsed['host'] ?? '');
216
- $ch = curl_init($url);
217
- curl_setopt_array($ch, [
218
- CURLOPT_RETURNTRANSFER => true,
219
- CURLOPT_FOLLOWLOCATION => true,
220
- CURLOPT_SSL_VERIFYPEER => false,
221
- CURLOPT_SSL_VERIFYHOST => false,
222
- CURLOPT_TIMEOUT => 18,
223
- CURLOPT_CONNECTTIMEOUT => 10,
224
- CURLOPT_COOKIEFILE => $cookieFile,
225
- CURLOPT_COOKIEJAR => $cookieFile,
226
- CURLOPT_ENCODING => 'gzip, deflate',
227
- CURLOPT_HTTPHEADER => [
228
- 'User-Agent: Mozilla/5.0 (Linux; Android 13; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36',
229
- 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
230
- 'Accept-Language: en-US,en;q=0.9,sw;q=0.8',
231
- 'Referer: ' . $host . '/',
232
- 'Cache-Control: no-cache',
233
- ],
234
- ]);
235
- $html = curl_exec($ch);
236
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
237
- $error = curl_error($ch);
238
- curl_close($ch);
239
- return ['html' => $html ?: '', 'code' => $httpCode, 'error' => $error];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  }
241
 
242
  // ═══════════════════════════════════════════════════════════
 
209
  // HTTP FETCH
210
  // ═══════════════════════════════════════════════════════════
211
 
212
+ /**
213
+ * Baadhi ya vyanzo (kraudiustv.iceiy.com) vinatumia anti-bot challenge
214
+ * ya kizamani (testcookie-nginx-module style): ukurasa unarudisha
215
+ * JavaScript inayotumia slowAES.decrypt(key, mode, iv, ciphertext) β€”
216
+ * matokeo yake yanawekwa kama cookie "__test", kisha ukurasa
217
+ * unapakiwa upya. Algorithm hii ni AES-128-CBC ya kawaida na
218
+ * inaweza kutatuliwa moja kwa moja hapa (hakuna haja ya JS engine).
219
+ */
220
+ function solveTestCookieChallenge(string $html): ?string {
221
+ if ($html === '' || stripos($html, 'slowAES') === false) return null;
222
+ if (!preg_match_all('/toNumbers\("([0-9a-fA-F]+)"\)/', $html, $m) || count($m[1]) < 3) return null;
223
+
224
+ [$keyHex, $ivHex, $cipherHex] = array_slice($m[1], 0, 3);
225
+ $key = @hex2bin($keyHex);
226
+ $iv = @hex2bin($ivHex);
227
+ $cipher = @hex2bin($cipherHex);
228
+ if ($key === false || $iv === false || $cipher === false) return null;
229
+
230
+ $decrypted = @openssl_decrypt($cipher, 'aes-128-cbc', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
231
+ if ($decrypted === false || $decrypted === '') return null;
232
+
233
+ return bin2hex($decrypted);
234
+ }
235
+
236
  function fetchPage(string $url): array {
237
  $cookieFile = sys_get_temp_dir() . '/jkr_' . md5($url) . '.txt';
238
  $parsed = parse_url($url);
239
  $host = ($parsed['scheme'] ?? 'https') . '://' . ($parsed['host'] ?? '');
240
+
241
+ $headers = [
242
+ 'User-Agent: Mozilla/5.0 (Linux; Android 13; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36',
243
+ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
244
+ 'Accept-Language: en-US,en;q=0.9,sw;q=0.8',
245
+ 'Referer: ' . $host . '/',
246
+ 'Cache-Control: no-cache',
247
+ ];
248
+
249
+ $doFetch = function(?string $extraCookie = null) use ($url, $cookieFile, $headers) {
250
+ $ch = curl_init($url);
251
+ $opts = [
252
+ CURLOPT_RETURNTRANSFER => true,
253
+ CURLOPT_FOLLOWLOCATION => true,
254
+ CURLOPT_SSL_VERIFYPEER => false,
255
+ CURLOPT_SSL_VERIFYHOST => false,
256
+ CURLOPT_TIMEOUT => 18,
257
+ CURLOPT_CONNECTTIMEOUT => 10,
258
+ CURLOPT_COOKIEFILE => $cookieFile,
259
+ CURLOPT_COOKIEJAR => $cookieFile,
260
+ CURLOPT_ENCODING => 'gzip, deflate',
261
+ CURLOPT_HTTPHEADER => $headers,
262
+ ];
263
+ if ($extraCookie !== null) $opts[CURLOPT_COOKIE] = $extraCookie;
264
+ curl_setopt_array($ch, $opts);
265
+ $html = curl_exec($ch);
266
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
267
+ $error = curl_error($ch);
268
+ curl_close($ch);
269
+ return ['html' => $html ?: '', 'code' => $httpCode, 'error' => $error];
270
+ };
271
+
272
+ $result = $doFetch();
273
+
274
+ $cookieVal = solveTestCookieChallenge($result['html']);
275
+ if ($cookieVal !== null) {
276
+ // Jaribio la 2: rudia request na cookie iliyotatuliwa
277
+ $retry = $doFetch("__test={$cookieVal}");
278
+ if ($retry['html']) {
279
+ $result = $retry;
280
+ if (solveTestCookieChallenge($result['html']) !== null) {
281
+ $result['error'] = $result['error'] ?: 'Anti-bot challenge haikutatuliwa (jaribio la 2 bado ni challenge)';
282
+ }
283
+ }
284
+ }
285
+
286
+ return $result;
287
  }
288
 
289
  // ═══════════════════════════════════════════════════════════