(07-04-2022, 01:03 PM)Tim Curtis Wrote: I think flac and wav are most often used with cue sheets.
There are a couple of places where .flac is assumed but I can prolly change that to also check for .wav or alternatively parse out the file extension from the FILE param in the cue sheet.
This is ehat I have done:
Code:
// CUE helper
function ensureAudioFile($path) {
$result = false;
$normalized = false;
$track = 'ANY';
// if (strpos($path, '.cue/track') != false) {
if (str_contains($path, '.cue/track')) {
$track = (int)str_replace('track', '', pathinfo($path, PATHINFO_BASENAME)); // e.g. "0001"
$path = pathinfo($path, PATHINFO_DIRNAME); // "filename.cue"
}
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if ('cue' == $ext) {
if (!str_starts_with($path, MPD_MUSICROOT)) {
$path = MPD_MUSICROOT . $path;
$normalized = true;
}
if (file_exists($path)) {
$lastfile = '';
$cuesheetlines = file($path);
$totlines = count($cuesheetlines);
$linendx = 0;
while (!$result && $linendx < $totlines) {
$line = trim($cuesheetlines[$linendx]);
if (str_starts_with($line, 'FILE ') && str_ends_with($line, ' WAVE')) {
$lastfile = pathinfo($path, PATHINFO_DIRNAME) . '/' . str_replace('"', '', str_replace('FILE ', '', str_replace(' WAVE', '', $line)));
}
else
if (str_starts_with($line, 'TRACK ')) {
$trackdata = explode(' ', $line, 3);
$tracknumber = (int)$trackdata[1];
if (('ANY' == $track) || ($track == $tracknumber)) {
$result = $lastfile;
}
}
$linendx++;
}
}
if ($normalized && str_starts_with($path, MPD_MUSICROOT)) {
$path = str_replace(MPD_MUSICROOT, '', $path);
}
}
else {
$result = $path;
}
return $result;
}
I call this function in getFileHash() and getCoverHash(), in playerlib.php, and also in coverart.php to normalize $path, just before the first check for $search_pri
This, no matter what, will give you the correct file to which the track belongs to. The function is defined in playerlib.php, of course. Works like a charm for me.
What do you think? (apart from the fact that you will write it better... I see I am no longer a skilled one in PHP...)
Cheers, Al.