* * Requires the PHP cURL extension (standard on cPanel). */ // ---- Config ------------------------------------------------------------ // NOTE: this key was taken from a third-party app. It can be revoked at any // time (then this breaks). For production, get your OWN key. define('PTB_API', 'https://api.playterabox.com/api/proxy'); define('PTB_SECRET', 'pk_hvetv821ruve5rhy2jfz7'); define('PTB_TIMEOUT', 60); // seconds — the API can be slow /** * Resolve a TeraBox share URL to file(s) with download links. * * @return array ['ok'=>true,'files'=>[...]] on success * ['ok'=>false,'error'=>'...'] on failure */ function terabox_resolve($shareUrl) { if (!function_exists('curl_init')) { return ['ok' => false, 'error' => 'PHP cURL extension is not enabled']; } $shareUrl = trim($shareUrl); if ($shareUrl === '') { return ['ok' => false, 'error' => 'Empty share URL']; } // Build the request URL with the share link PROPERLY encoded. $endpoint = PTB_API . '?secret=' . urlencode(PTB_SECRET) . '&url=' . urlencode($shareUrl); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $endpoint, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => PTB_TIMEOUT, CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_ENCODING => '', // handle gzip CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101 Firefox/121.0', CURLOPT_HTTPHEADER => ['Accept: application/json'], ]); $body = curl_exec($ch); $errno = curl_errno($ch); $errmsg = curl_error($ch); $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($errno) { return ['ok' => false, 'error' => "Network error: $errmsg"]; } if ($status !== 200) { return ['ok' => false, 'error' => "API returned HTTP $status", 'raw' => substr($body, 0, 300)]; } $data = json_decode($body, true); if (!is_array($data)) { return ['ok' => false, 'error' => 'API did not return valid JSON', 'raw' => substr($body, 0, 300)]; } if (($data['status'] ?? '') !== 'success') { return ['ok' => false, 'error' => $data['message'] ?? 'API reported failure', 'raw' => $data]; } // Normalize the file list into a clean shape. $files = []; foreach (($data['list'] ?? []) as $item) { if (!is_array($item)) { continue; } $files[] = [ 'name' => $item['name'] ?? 'Unknown', 'size' => $item['size'] ?? 0, 'size_formatted' => $item['size_formatted'] ?? '', 'type' => $item['type'] ?? '', 'download_link' => $item['normal_dlink'] ?? '', 'stream_url' => $item['stream_url'] ?? '', 'fast_stream' => $item['fast_stream_url'] ?? null, 'thumbnail' => $item['thumbnail'] ?? '', 'fs_id' => $item['fs_id'] ?? '', ]; } if (!$files) { return ['ok' => false, 'error' => 'No files found in share']; } return ['ok' => true, 'total' => count($files), 'files' => $files]; } // ---- Web endpoint mode ------------------------------------------------- // If called directly with ?url=..., output JSON. if (basename($_SERVER['SCRIPT_FILENAME'] ?? '') === basename(__FILE__) && isset($_GET['url'])) { header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); $result = terabox_resolve($_GET['url']); http_response_code($result['ok'] ? 200 : 502); echo json_encode($result, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; }