mirror of
https://github.com/koel/koel
synced 2024-12-19 00:53:05 +00:00
33 lines
789 B
PHP
33 lines
789 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
use Throwable;
|
|
|
|
class SimpleLrcReader
|
|
{
|
|
public function tryReadForMediaFile(string $mediaFilePath): string
|
|
{
|
|
$lrcFilePath = self::getLrcFilePath($mediaFilePath);
|
|
|
|
try {
|
|
return $lrcFilePath ? trim(File::get($lrcFilePath)) : '';
|
|
} catch (Throwable) {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
private static function getLrcFilePath(string $mediaFilePath): ?string
|
|
{
|
|
foreach (['.lrc', '.LRC'] as $extension) {
|
|
$lrcFilePath = preg_replace('/\.[^.]+$/', $extension, $mediaFilePath);
|
|
|
|
if (File::isFile($lrcFilePath) && File::isReadable($lrcFilePath)) {
|
|
return $lrcFilePath;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|