From 83b20babf0f0accebcaf30c1f24f48812739b1cd Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Tue, 26 Nov 2024 15:08:24 +0000 Subject: [PATCH] finessed previous revision --- ui/Editor.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/Editor.php b/ui/Editor.php index 568dad5c..46eca607 100644 --- a/ui/Editor.php +++ b/ui/Editor.php @@ -310,8 +310,8 @@ private function prefillTracks() { // where (22) is an optional suffix. // We want only the last word, exclusive the suffix // (in this case, 'Wilson'). - $artist = isset($track->artists) && - preg_match('/(\w+)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches) ? $matches[1] . ': ' : ''; + $artist = !empty($track->artists) && + preg_match('/(\w+)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches) ? "{$matches[1]}: " : ''; foreach($track->sub_tracks as $track) { $entry = []; @@ -320,6 +320,11 @@ private function prefillTracks() { $entry["time"] = trim($track->duration); $entry["title"] = mb_substr($artist . trim($track->title), 0, PlaylistEntry::MAX_FIELD_LENGTH); + // strip optional numeric suffix from artist name + if(!empty($track->artists) && + preg_match('/^(.+?)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches)) + $entry["artist"] = mb_substr(trim($matches[1]), 0, PlaylistEntry::MAX_FIELD_LENGTH); + $tracks[] = $entry; } continue; @@ -339,7 +344,7 @@ private function prefillTracks() { $entry["time"] = trim($track->duration); $entry["title"] = mb_substr(trim($track->title) . $artist, 0, PlaylistEntry::MAX_FIELD_LENGTH); // strip optional numeric suffix from artist name - if($track->artists && + if(!empty($track->artists) && preg_match('/^(.+?)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches)) $entry["artist"] = mb_substr(trim($matches[1]), 0, PlaylistEntry::MAX_FIELD_LENGTH);