X-Git-Url: https://git.hcoop.net/clinton/abcde.git/blobdiff_plain/43bd68def74d74ee0676674ecc1eb2e6caedcb25..efe231408623824b96b906019901eb35b38524be:/abcde-musicbrainz-tool diff --git a/abcde-musicbrainz-tool b/abcde-musicbrainz-tool index 8a7391e..4f2021b 100644 --- a/abcde-musicbrainz-tool +++ b/abcde-musicbrainz-tool @@ -43,6 +43,12 @@ if (!defined($workdir)) { $workdir = "/tmp"; } +sub calc_sha1($) { + my $filename = shift; + my $s = Digest::SHA->new(1); + $s->addfile($filename); + return $s->hexdigest; +} if ($command =~ m/^id/) { my $disc = new MusicBrainz::DiscID($device); @@ -68,6 +74,7 @@ if ($command =~ m/^id/) { my $response = $ws->search({ DISCID => $discid }); my @releases = $response->release_list(); my $releasenum = 0; + my @sums; foreach my $release (@releases) { my $a_artist = $release->artist()->name(); @@ -119,6 +126,18 @@ if ($command =~ m/^id/) { print OUT "PLAYORDER=\n"; print OUT ".\n"; close OUT; + + # Check to see that this entry is unique; generate a checksum + # and compare to any previous checksums + my $checksum = calc_sha1("$workdir/cddbread.$releasenum"); + foreach my $sum (@sums) { + if ($checksum eq $sum) { + unlink("$workdir/cddbread.$releasenum"); + $releasenum--; + last; + } + } + push (@sums, $checksum); } } elsif ($command =~ m/calcid/) { # Calculate MusicBrainz ID from disc offsets; see