home
/
aioutajg
/
playpauseonline.com
/
api
/
Go to Home Directory
+
Upload
Create File
root@0UT1S:~$
Execute
By Order of Mr.0UT1S
[DIR] ..
N/A
index.php
0 bytes
Rename
Delete
process.php
3.23 KB
Rename
Delete
rate_limit.log
20 bytes
Rename
Delete
<?php header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Methods: POST, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type'); // API Endpoint: process.php require_once __DIR__ . '/../includes/config.php'; try { // Validate request if ($_SERVER['REQUEST_METHOD'] !== 'POST') { throw new Exception('Invalid request method', 405); } // Get raw POST data $input = json_decode(file_get_contents('php://input'), true); if (empty($input['videoUrl'])) { throw new Exception('Video URL is required', 400); } // Sanitize input $videoUrl = sanitize_input($input['videoUrl']); $videoId = extract_video_id($videoUrl); if (!$videoId || !is_valid_video_id($videoId)) { throw new Exception('Invalid YouTube URL format', 400); } // Rate limiting $ip = $_SERVER['REMOTE_ADDR']; $logFile = __DIR__ . '/rate_limit.log'; $requests = json_decode(file_get_contents($logFile), true) ?: []; if (($requests[$ip] ?? 0) >= RATE_LIMIT) { throw new Exception('Rate limit exceeded. Try again later.', 429); } // Get video details from YouTube API $apiUrl = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id={$videoId}&key=" . YT_API_KEY; $response = @file_get_contents($apiUrl); if ($response === false) { throw new Exception('YouTube API request failed', 500); } $data = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('Invalid API response', 500); } if (empty($data['items'][0])) { throw new Exception('Video not found', 404); } $snippet = $data['items'][0]['snippet']; $thumbnails = process_thumbnails($snippet['thumbnails']); // Build response $responseData = build_api_response($snippet, $thumbnails); // Update rate limit log $requests[$ip] = ($requests[$ip] ?? 0) + 1; file_put_contents($logFile, json_encode($requests)); // Send JSON response header('Content-Type: application/json'); echo json_encode($responseData); exit(); } catch (Exception $e) { http_response_code($e->getCode() ?: 400); echo json_encode([ 'success' => false, 'message' => $e->getMessage() ]); exit(); } // Helper functions function extract_video_id($url) { $patterns = [ '/youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/', '/youtu\.be\/([a-zA-Z0-9_-]{11})/', '/youtube\.com\/embed\/([a-zA-Z0-9_-]{11})/', '/youtube\.com\/v\/([a-zA-Z0-9_-]{11})/' ]; foreach ($patterns as $pattern) { if (preg_match($pattern, $url, $matches)) { return $matches[1]; } } return null; } function process_thumbnails($thumbnails) { $processed = []; foreach ($thumbnails as $quality => $thumb) { $processed[] = [ 'url' => $thumb['url'], 'width' => $thumb['width'], 'height' => $thumb['height'], 'resolution' => "{$thumb['width']}x{$thumb['height']}", 'quality' => ucfirst($quality) ]; } return $processed; } ?>
Save