Skip to content

Commit

Permalink
revised discogs subtracks to include index track title; removed extra…
Browse files Browse the repository at this point in the history
…artists
  • Loading branch information
RocketMan committed Dec 2, 2024
1 parent 9aab431 commit 08e49bc
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions ui/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,16 @@ private function prefillTracks() {
$addUrls = $this->getUrlAutofill();
foreach($json->tracklist as $track) {
if($track->type_ == "index") {
// The artist name is formatted like:
// Richard Wilson (22)
// where (22) is an optional suffix.
// We want only the last word, exclusive the suffix
// (in this case, 'Wilson').
$artist = !empty($track->artists) &&
preg_match('/(\w+)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches) ? "{$matches[1]}: " : '';
$title = !empty($track->title) &&
preg_match('/^(.+?)(?:\s\(.+\))?$/', $track->title, $matches) ?
"{$matches[1]}: " : '';

foreach($track->sub_tracks as $track) {
$entry = [];
$entry["seq"] = ++$seq;
$entry["oseq"] = trim($track->position);
$entry["time"] = trim($track->duration);
$entry["title"] = mb_substr($artist . trim($track->title), 0, PlaylistEntry::MAX_FIELD_LENGTH);
$entry["title"] = mb_substr($title . trim($track->title), 0, PlaylistEntry::MAX_FIELD_LENGTH);

// strip optional numeric suffix from artist name
if(!empty($track->artists) &&
Expand All @@ -333,16 +329,11 @@ private function prefillTracks() {
if($track->type_ != "track")
continue;

// see comment above about the artist name format
$artist = isset($_GET["artist"]) &&
!empty($track->extraartists) &&
preg_match('/(\w+)(?:\s\(\d+\))?$/', $track->extraartists[0]->name, $matches) ? " ({$matches[1]})" : '';

$entry = [];
$entry["seq"] = ++$seq;
$entry["oseq"] = trim($track->position);
$entry["time"] = trim($track->duration);
$entry["title"] = mb_substr(trim($track->title) . $artist, 0, PlaylistEntry::MAX_FIELD_LENGTH);
$entry["title"] = mb_substr(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))
Expand Down

0 comments on commit 08e49bc

Please sign in to comment.