31 lines
796 B
PHP
31 lines
796 B
PHP
<?php
|
|
|
|
namespace App\Domain\Media;
|
|
|
|
class HlsPlaylist
|
|
{
|
|
public function rewrite(string $playlist, string $playlistPath, callable $sign): string
|
|
{
|
|
$directory = str_replace('\\', '/', dirname($playlistPath));
|
|
$lines = preg_split("/\r\n|\n|\r/", $playlist) ?: [];
|
|
$rewritten = [];
|
|
|
|
foreach ($lines as $line) {
|
|
$value = trim($line);
|
|
|
|
if ($value === '' || str_starts_with($value, '#')) {
|
|
$rewritten[] = $line;
|
|
|
|
continue;
|
|
}
|
|
|
|
$target = str_starts_with($value, 'ableitungen/')
|
|
? $value
|
|
: ($directory === '.' ? $value : $directory.'/'.$value);
|
|
$rewritten[] = $sign($target);
|
|
}
|
|
|
|
return implode("\n", $rewritten)."\n";
|
|
}
|
|
}
|