fork download
  1. <?php
  2.  
  3. function extractSubM3U8Urls($m3u8Url) {
  4. $baseUrl = dirname($m3u8Url);
  5. $content = @file_get_contents($m3u8Url);
  6.  
  7. if (!$content) {
  8. return ["error" => "file_get_contents failed. Possibly blocked or disabled."];
  9. }
  10.  
  11. $lines = explode("\n", $content);
  12. $subUrls = [];
  13.  
  14. foreach ($lines as $line) {
  15. $line = trim($line);
  16.  
  17. if ($line === '' || str_starts_with($line, '#')) continue;
  18.  
  19. if (!preg_match('/^https?:\/\//', $line)) {
  20. $line = rtrim($baseUrl, '/') . '/' . ltrim($line, '/');
  21. }
  22.  
  23. $subUrls[] = $line;
  24. }
  25.  
  26. return $subUrls;
  27. }
  28.  
  29. // Test URL
  30. $m3u8Url = 'https://i...content-available-to-author-only...s.com/vidarka/Guy-Tries-To-CHEAT-On-DRIVING-TEST--He-Lives-To-Regret-It-5e764876529329c6b47a154de8713578/hls/master.m3u8';
  31. $subUrls = extractSubM3U8Urls($m3u8Url);
  32.  
  33. echo json_encode($subUrls, JSON_PRETTY_PRINT);
  34.  
Success #stdin #stdout 0.04s 26084KB
stdin
Standard input is empty
stdout
{
    "error": "file_get_contents failed. Possibly blocked or disabled."
}