Skip to content

Commit

Permalink
finessed previous revision
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Nov 26, 2024
1 parent d5262b3 commit 83b20ba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ui/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 83b20ba

Please sign in to comment.