| <?php |
| |
| header('Content-Type: application/json'); |
|
|
| |
| header('Cache-Control: no-cache, no-store, must-revalidate'); |
| header('Pragma: no-cache'); |
| header('Expires: 0'); |
|
|
| |
| $videoDir = 'videos'; |
|
|
| |
| $videos = glob($videoDir . '/*.mp4'); |
|
|
| |
| if ($videos === false || count($videos) === 0) { |
| $response = [ |
| "code" => 500, |
| "msg" => "No videos found", |
| "videos" => null |
| ]; |
| } else { |
| |
| $randomVideo = $videos[array_rand($videos)]; |
| $videoUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $randomVideo; |
|
|
| |
| $response = [ |
| "code" => 200, |
| "msg" => "success", |
| "videos" => $videoUrl |
| ]; |
| } |
|
|
| |
| $jsonResponse = json_encode($response); |
|
|
| |
| $jsonResponse = str_replace('\/', '/', $jsonResponse); |
|
|
| |
| echo $jsonResponse; |
| ?> |
|
|