Skip to content

Commit ef5c4b9

Browse files
Merge pull request #1338 from darrell-k/fix-mb-tags-cue-v2
Also clean/validate cue tags
2 parents f03a30e + 1fc09ad commit ef5c4b9

File tree

4 files changed

+40
-119
lines changed

4 files changed

+40
-119
lines changed

Slim/Formats.pm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,13 @@ sub readTags {
275275

276276
main::DEBUGLOG && $isDebug && $log->debug("Report for $file:");
277277

278-
# XXX: can Audio::Scan make these regexes unnecessary?
278+
sanitizeTagValues($tags, $file);
279+
280+
return $tags;
281+
}
282+
283+
sub sanitizeTagValues {
284+
my ($tags, $file) = @_;
279285

280286
# Bug: 2381 - FooBar2k seems to add UTF8 boms to their values.
281287
# Bug: 3769 - Strip trailing nulls
@@ -286,7 +292,7 @@ sub readTags {
286292
my $original = $value;
287293

288294
use bytes;
289-
if ( my $cached = $tagCache{$value} ) {
295+
if ( my $cached = $tagCache{$tag}{$value} ) {
290296
$tags->{$tag} = $cached;
291297
next;
292298

@@ -329,17 +335,15 @@ sub readTags {
329335
$value = $tags->{$tag} = \@mbIDs;
330336
}
331337

332-
$tagCache{$original} = $value;
338+
$tagCache{$tag}{$original} = $value;
333339
}
334340

335-
main::DEBUGLOG && $isDebug && $value && $log->debug(". $tag : $value");
341+
main::DEBUGLOG && $log->is_debug && $value && $log->debug(". $tag : $value");
336342
}
337343

338344
if (scalar (keys %tagCache) > 50) {
339345
%tagCache = ();
340346
}
341-
342-
return $tags;
343347
}
344348

345349
1;

Slim/Formats/FLAC.pm

Lines changed: 10 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ sub getTag {
133133
# suck in metadata for all these tags
134134
my $items = $class->_getSubFileTags($s, $tracks);
135135

136+
foreach (values %$tracks) {
137+
Slim::Formats::sanitizeTagValues($_, $file);
138+
}
139+
136140
# fallback if we can't parse metadata
137141
if ( $items < 1 ) {
138142
logWarning("Unable to find metadata for tracks referenced by cuesheet: [$file]");
@@ -217,13 +221,13 @@ sub _getStandardTag {
217221
my $tags = $s->{tags} || {};
218222

219223
$class->_addInfoTags($s, $tags);
220-
$class->_doTagMapping($tags);
224+
$class->doTagMapping($tags);
221225
$class->_addArtworkTags($s, $tags);
222226

223227
return $tags;
224228
}
225229

226-
sub _doTagMapping {
230+
sub doTagMapping {
227231
my ($class, $tags) = @_;
228232

229233
# Map ID3 tags first, so FLAC tags win out
@@ -349,10 +353,6 @@ sub _getSubFileTags {
349353
$items = $class->_getCUEinVCs($s, $tracks);
350354
return $items if $items > 0;
351355

352-
# try parsing stacked vorbis comments
353-
$items = $class->_getStackedVCs($s, $tracks);
354-
return $items if $items > 0;
355-
356356
# This won't yield good results - but without it, we regress from 6.0.2
357357
my $tags = $class->_getStandardTag($s);
358358

@@ -532,7 +532,7 @@ sub _getXMLTags {
532532

533533
%{$tracks->{$cuesheetTrack}} = (%{$defaultTags}, %{$tracks->{$cuesheetTrack}});
534534

535-
$class->_doTagMapping($tracks->{$cuesheetTrack});
535+
$class->doTagMapping($tracks->{$cuesheetTrack});
536536
}
537537
}
538538

@@ -627,7 +627,7 @@ sub _getNumberedVCs {
627627

628628
%{$tracks->{$num}} = (%{$defaultTags}, %{$tracks->{$num}});
629629

630-
$class->_doTagMapping($tracks->{$num});
630+
$class->doTagMapping($tracks->{$num});
631631

632632
$tracks->{$num}->{TRACKNUM} = $num unless exists $tracks->{$num}->{TRACKNUM};
633633
}
@@ -726,7 +726,7 @@ sub _getCDDBTags {
726726

727727
%{$tracks->{$key}} = (%{$tags}, %{$tracks->{$key}});
728728

729-
$class->_doTagMapping($tracks->{$key});
729+
$class->doTagMapping($tracks->{$key});
730730
}
731731

732732
return $items;
@@ -783,115 +783,14 @@ sub _getCUEinVCs {
783783
}
784784
}
785785

786-
$class->_doTagMapping($tracks->{$key});
786+
$class->doTagMapping($tracks->{$key});
787787

788788
$items++;
789789
}
790790

791791
return $items;
792792
}
793793

794-
sub _getStackedVCs {
795-
my ($class, $s, $tracks) = @_;
796-
797-
my $items = 0;
798-
799-
# XXX: can't support this using Audio::Scan, this is a stupid tag scheme anyway!
800-
return 0;
801-
802-
=pod
803-
# parse "stacked" vorbis comments
804-
# this is tricky when it comes to matching which groups belong together
805-
# particularly for various artist, or multiple album compilations.
806-
# this as also not terribly efficent, so it's not our first choice.
807-
808-
# here's a simple example of the sort of thing we're trying to work with
809-
#
810-
# ARTIST=foo
811-
# ALBUM=bar
812-
# TRACKNUMBER=1
813-
# TITLE=baz
814-
# TRACKNUMBER=2
815-
# TITLE=something
816-
817-
# grab the raw comments for parsing
818-
my $rawTags = $flac->{'rawTags'};
819-
820-
# grab the cuesheet for reference
821-
my $cuesheet = $flac->cuesheet();
822-
823-
# validate number of TITLE tags against number of
824-
# tracks in the cuesheet
825-
my $titletags = 0;
826-
my $cuetracks = 0;
827-
828-
for my $tag (@$rawTags) {
829-
$titletags++ if $tag =~ /^\s*TITLE=/i;
830-
}
831-
832-
for my $track (@$cuesheet) {
833-
$cuetracks++ if $track =~ /^\s*TRACK/i;
834-
}
835-
836-
return 0 unless $titletags == $cuetracks;
837-
838-
839-
# ok, let's see which tags apply to which tracks
840-
841-
my $tempTags = {};
842-
my $defaultTags = {};
843-
844-
$class->_addInfoTags($flac, $defaultTags);
845-
846-
for my $tag (@$rawTags) {
847-
848-
# Match the key and value
849-
if ($tag =~ /^(.*?)=(.*?)[\r\n]*$/) {
850-
851-
# Make the key uppercase
852-
my $tkey = uc($1);
853-
my $value = $2;
854-
855-
# use duplicate detection to find track boundries
856-
# retain file wide values as defaults
857-
if (defined $tempTags->{$tkey}) {
858-
$items++;
859-
my %merged = (%{$defaultTags}, %{$tempTags});
860-
$defaultTags = \%merged;
861-
$tempTags = {};
862-
863-
# set the tags on the track
864-
%{$tracks->{$items}} = (%{$tracks->{$items}}, %{$defaultTags});
865-
866-
$class->_doTagMapping($tracks->{$items});
867-
868-
if (!exists $tracks->{$items}->{'TRACKNUM'}) {
869-
$tracks->{$items}->{'TRACKNUM'} = $items;
870-
}
871-
872-
}
873-
874-
$tempTags->{$tkey} = $value;
875-
876-
main::DEBUGLOG && logger('formats.playlists')->debug(" $tkey: $value");
877-
}
878-
}
879-
880-
# process the final track
881-
$items++;
882-
883-
%{$tracks->{$items}} = (%{$tracks->{$items}}, %{$defaultTags}, %{$tempTags});
884-
885-
$class->_doTagMapping($tracks->{$items});
886-
887-
if (!exists $tracks->{$items}->{'TRACKNUM'}) {
888-
$tracks->{$items}->{'TRACKNUM'} = $items;
889-
}
890-
891-
return $items;
892-
=cut
893-
}
894-
895794
=head2 findFrameBoundaries( $fh, $offset, $time )
896795
897796
Returns offset to audio frame containing $time.

Slim/Formats/Playlists/CUE.pm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ sub parse {
367367
}
368368
} else {
369369

370-
# handle remaning Commands as a list of keys and values.
370+
# handle remaining Commands as a list of keys and values.
371371
($cuesheet, $tracks) = _addCommand($cuesheet,
372372
$tracks,
373373
$inAlbum,
@@ -564,6 +564,20 @@ sub parse {
564564

565565
# Everything in a cue sheet should be marked as audio.
566566
$track->{'AUDIO'} = 1;
567+
568+
# external cue sheet hasn't been through tag mapping, so do it now.
569+
if ( !$embedded && $track->{'FILENAME'} ) {
570+
if ( my $type = Slim::Music::Info::typeFromPath(Slim::Utils::Misc::pathFromFileURL($track->{'FILENAME'})) ) {
571+
if ( my $tagReaderClass = Slim::Formats->classForFormat($type) ) {
572+
Slim::Formats->loadTagFormatForType($type);
573+
if ( $tagReaderClass->can('doTagMapping') ) {
574+
$tagReaderClass->doTagMapping($track);
575+
}
576+
}
577+
}
578+
}
579+
580+
Slim::Formats::sanitizeTagValues($track, $filename);
567581
}
568582

569583
# Bug 8443, if no tracks contain a URI element, it's an invalid cue

Slim/Schema.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ sub _createOrUpdateAlbum {
912912
my $disc = $attributes->{DISC};
913913
my $discc = $attributes->{DISCC};
914914
# Bug 10583 - Also check for MusicBrainz Album Id
915-
my $brainzId = $attributes->{MUSICBRAINZ_ALBUM_ID}[0]; # Surely there is only one MB album id!
915+
# Surely there is only one MB album id!
916+
my $brainzId = ref $attributes->{MUSICBRAINZ_ALBUM_ID} ? $attributes->{MUSICBRAINZ_ALBUM_ID}[0] : $attributes->{MUSICBRAINZ_ALBUM_ID};
916917
my $extId = $attributes->{EXTID} || $attributes->{ALBUM_EXTID};
917918

918919
# if we have a disc number from an online service, default disc count to 1
@@ -2643,6 +2644,9 @@ sub _preCheckAttributes {
26432644

26442645
# Normalize attribute names
26452646
while ( my ($key, $val) = each %{ $args->{'attributes'} } ) {
2647+
if ( $key =~ /^MUSICBRAINZ.*ID$/ && $val && ref $val ne 'ARRAY' ) {
2648+
logWarning("$key ($val) in " . Slim::Utils::Misc::pathFromFileURL($url) . " has not been validated by Slim::Formats::sanitizeTagValues");
2649+
}
26462650
# don't overwrite mapped values
26472651
next if $mappedValues{$key};
26482652

0 commit comments

Comments
 (0)