Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Upcoming moOde 8.1.2 release
#10
(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.
Reply


Messages In This Thread
Upcoming moOde 8.1.2 release - by Tim Curtis - 07-03-2022, 03:39 AM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-03-2022, 10:29 AM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-03-2022, 12:04 PM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-03-2022, 04:01 PM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-03-2022, 04:43 PM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-03-2022, 04:57 PM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-03-2022, 05:25 PM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-04-2022, 09:34 AM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-04-2022, 01:03 PM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-04-2022, 01:25 PM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-04-2022, 09:32 PM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-04-2022, 09:34 PM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-09-2022, 01:13 PM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-09-2022, 09:49 PM
RE: Upcoming moOde 8.1.2 release - by Tim Curtis - 07-09-2022, 10:16 PM
RE: Upcoming moOde 8.1.2 release - by Nutul - 07-09-2022, 11:19 PM

Forum Jump: