MediaHlsService.php 616 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Services\Media;
  3. use Storage;
  4. class MediaHlsService
  5. {
  6. public static function allFiles($media)
  7. {
  8. $path = $media->media_path;
  9. if(!$path) { return; }
  10. $parts = explode('/', $path);
  11. $filename = array_pop($parts);
  12. $dir = implode('/', $parts);
  13. [$name, $ext] = explode('.', $filename);
  14. $files = Storage::files($dir);
  15. return collect($files)
  16. ->filter(function($p) use($dir, $name) {
  17. return str_starts_with($p, $dir . '/' . $name);
  18. })
  19. ->values()
  20. ->toArray();
  21. }
  22. }