]> diplodocus.org Git - flac-archive/commitdiff
add fa-mb for querying MusicBrainz
authorEric Gillespie <epg@pretzelnet.org>
Sat, 6 Aug 2022 01:07:21 +0000 (20:07 -0500)
committerEric Gillespie <epg@pretzelnet.org>
Sat, 6 Aug 2022 01:07:21 +0000 (20:07 -0500)
quick n dirty hack, just like everything else here!

fa-mb [new file with mode: 0755]
t/mb.t [new file with mode: 0644]

diff --git a/fa-mb b/fa-mb
new file mode 100755 (executable)
index 0000000..4c6107a
--- /dev/null
+++ b/fa-mb
@@ -0,0 +1,231 @@
+#!/usr/local/bin/perl
+
+=head1 NAME
+
+B<fa-mb> - Query MusicBrainz
+
+=head1 SYNOPSIS
+
+B<fa-mb> B<-Q> B<ARTIST> B<TITLE>
+B<fa-mb> [B<-p>] B<RELEASE-ID>
+
+=head1 DESCRIPTION
+
+The first form queries for releases by B<ARTIST> and B<TITLE>, listing a
+summary, one per line.  The first column is the id, which is used as the
+B<RELEASE-ID> argument to the second form.
+
+The second form looks up a release by B<RELEASE-ID>, listing all the tags for
+each disc in the release in the form expected by B<fa-rip>.
+
+The second form accepts a B<-p> option which enables the PAREN HACK, which is
+quite gross.  I like to put information such as "(live)" in the VERSION tag
+rather than TITLE tag.  This information comes out of MusicBrainz parenthesized
+at the end of the track title, so this just strips out any parenthesized parts.
+Frequently it is incorrect:  pay attention!
+
+The tags listing also hacks various Unicode characters that work just fine with
+their ASCII equivalents, e.g. quotation marks.
+
+=cut
+
+package epg::flac::archive::mb;
+
+use v5.12;
+use utf8;
+use warnings;
+
+use Exporter 'import';
+use JSON::PP;
+
+use URI::Escape;
+
+our @EXPORT_OK = qw[
+       format_tags
+        list_releases
+        read_releases
+       read_release
+    ];
+
+sub tracks {
+       local $_;
+       my $tracks = shift;
+       [
+        map {
+                $_ = $_->{title};
+                # unicode hacks
+                s/‐/-/g;
+                s/’/'/g;
+                $_
+        } @$tracks
+       ]
+}
+
+sub read_release {
+       local $_;
+       my $parsed = decode_json(shift);
+       my $release = release_metadata($parsed);
+       # TODO this is dumb.  put it into release_metadata
+       # TODO only include "format": "CD" (i.e. exclude "format": "DVD-Video")
+       $release->{discs} = [map { tracks($_->{tracks}) } @{$parsed->{media}}];
+       $release
+}
+
+sub release_metadata {
+       local $_ = shift;
+       my $date = $_->{date} // 'UNKNOWN';
+       my $events = $_->{'release-events'};
+       if (defined($events)) {
+               if (@$events > 1) {
+                       warn('found example of multiple release events!');
+               }
+               my $event_date = $events->[0]->{date};
+               if (defined($event_date)) {
+                       if ($event_date ne $date) {
+                               warn("release-events has date $event_date (vs. $date)");
+                       }
+               }
+       }
+       my ($discs, $tracks) = (0, 0);
+       for my $m (@{$_->{media} // []}) {
+               $discs += $m->{'disc-count'} // 0;
+               $tracks += $m->{'track-count'} // 0;
+       }
+       if ($tracks == 0 && defined($_->{'disc-count'})) {
+               $tracks = $_->{'disc-count'};
+       }
+       if (defined($_->{'disc-count'})) {
+               warn('disc count defined at release root!');
+       }
+       my $artist;
+       my $artcred = $_->{'artist-credit'};
+       if (defined($artcred)) {
+               $artist = join('', map {
+                       # warn('HEYEPG! ', join(', ', keys(%$_)));
+                       # warn("HEYEPG ", $_->{name}, 'join=', ($_->{joinphrase} // ''));
+                       $_->{name}, ($_->{joinphrase} // '') } @$artcred);
+       } else {
+               warn('OH!');
+       }
+       {
+               id              => $_->{id},
+               artist          => $artist // 'UNKNOWN',
+               title           => $_->{title},
+               discs           => $discs,
+               tracks          => $tracks,
+               country         => $_->{country} // '--',
+               date            => $date,
+               labels          => join(', ', map { $_->{label}->{name} // 'UNKNOWN' } @{$_->{'label-info'} // []}),
+               disambiguation  => $_->{disambiguation} // '',
+               status          => $_->{status},
+       }
+}
+
+sub read_releases {
+       local $_;
+       my $parsed = decode_json(shift);
+       [map { release_metadata($_) } @{$parsed->{releases}}]
+}
+
+sub list_releases {
+       local $_;
+       my $releases = shift;
+       join("\n",
+            map {
+                    sprintf('%s %-10s %3d tracks / %2d discs in %s %s by %s; %s, %s',
+                            $_->{id}, $_->{date},
+                            $_->{tracks}, $_->{discs},
+                            $_->{country}, $_->{title}, $_->{labels}
+                            , $_->{disambiguation}, $_->{status},
+                        )
+            } @$releases)
+}
+
+sub format_tags {
+       local $_;
+       my %parm = @_;
+       my $hack_parens = $parm{hack_parens} // 0;
+       my $release = $parm{release};
+       my $artist = 'ARTIST=' . $release->{artist};
+       my $album = 'ALBUM=' . $release->{title};
+       my $date = 'DATE=' . $release->{date};
+       my $discs = $release->{discs};
+       my $multi = @$discs > 1;
+       my $d = 0;
+       join("\n",
+            map {
+                    my @discnum;
+                    if ($multi) {
+                            $d++;
+                            @discnum = ("DISCNUMBER=$d");
+                    }
+                    my $t = 0;
+                    (
+                     $artist, $album, $date, @discnum,
+                     map {
+                             $t++;
+                             my @tags;
+                             if ($hack_parens) {
+                                     /([^(]+)(.*)/;
+                                     my $title = $1;
+                                     my $version = $2;
+                                     if (length($version)) {
+                                             $title =~ s/\s+$//;
+                                             $version =~ s/^\(//;
+                                             $version =~ s/\)$//;
+                                             @tags = ("TITLE[$t]=$title", "VERSION[$t]=$version");
+                                     } else {
+                                             @tags = ("TITLE[$t]=$title")
+                                     }
+                             } else {
+                                     @tags = ("TITLE[$t]=$_");
+                             }
+                             @tags
+                     } @$_
+                    )
+            } @$discs
+           )
+}
+
+sub main {
+       my $arg = shift || die;
+       if ($arg eq '-Q') {
+               my $artist = shift || die;
+               my $title = shift || die;
+               my $url =
+                   'https://musicbrainz.org/ws/2/release?query='
+                   . uri_escape("artist:\"$artist\" AND \"$title\" AND format:CD");
+               open(my $fh, '-|', 'curl', '--silent', '-Haccept:application/json', $url)
+                   || die;
+               my @body;
+               while (<$fh>) {
+                       push(@body, $_);
+               }
+               say(list_releases(read_releases(join('', @body))));
+       } else {
+               my $hack_parens;
+               if ($arg eq '-p') {
+                       $arg = shift || die;
+                       $hack_parens = 1;
+               } else { $hack_parens = 0 }
+               my $url = "https://musicbrainz.org/ws/2/release/$arg?inc=artist-credits+recordings";
+               open(my $fh, '-|', 'curl', '--silent', '-Haccept:application/json', $url)
+                   || die;
+               say(format_tags(
+                           hack_parens => $hack_parens,
+                           release => read_release(join('', <$fh>)),
+                   ));
+       }
+       0
+}
+
+if (!caller) {
+       exit(main(@ARGV))
+}
+
+1;
+
+# Local variables:
+# perl-indent-level: 8
+# indent-tabs-mode: t
+# End:
diff --git a/t/mb.t b/t/mb.t
new file mode 100644 (file)
index 0000000..e62a798
--- /dev/null
+++ b/t/mb.t
@@ -0,0 +1,1589 @@
+use v5.12;
+use warnings;
+
+use Test::More tests => 2;
+
+require './fa-mb';
+epg::flac::archive::mb->import(
+    qw[
+       format_tags
+        list_releases
+        read_releases
+       read_release
+    ]);
+
+my ($in, $out);
+
+$in = <<'EOF';
+{
+   "offset" : 0,
+   "releases" : [
+      {
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "asin" : "B000005RQF",
+         "id" : "1f233a68-c3c2-348b-a135-10edc450edf7",
+         "track-count" : 18,
+         "release-events" : [
+            {
+               "date" : "1993",
+               "area" : {
+                  "id" : "89a675c2-3e37-3518-b83c-418bad59a85a",
+                  "iso-3166-1-codes" : [
+                     "XE"
+                  ],
+                  "name" : "Europe",
+                  "sort-name" : "Europe"
+               }
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M.",
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+               }
+            }
+         ],
+         "country" : "XE",
+         "date" : "1993",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "barcode" : "077771320125",
+         "media" : [
+            {
+               "track-count" : 18,
+               "disc-count" : 4,
+               "format" : "CD"
+            }
+         ],
+         "label-info" : [
+            {
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               },
+               "catalog-number" : "0777 7 13201 2 5"
+            }
+         ],
+         "packaging" : "Jewel Case",
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "release-group" : {
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant",
+            "primary-type" : "Album"
+         },
+         "count" : 1,
+         "score" : 100,
+         "disambiguation" : "The I.R.S. Years Vintage 1986",
+         "status" : "Official"
+      },
+      {
+         "score" : 100,
+         "status" : "Official",
+         "media" : [
+            {
+               "format" : "CD",
+               "disc-count" : 13,
+               "track-count" : 12
+            }
+         ],
+         "label-info" : [
+            {
+               "label" : {
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03",
+                  "name" : "I.R.S. Records"
+               },
+               "catalog-number" : "72434-93478-2-3"
+            }
+         ],
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "release-group" : {
+            "primary-type" : "Album",
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939"
+         },
+         "count" : 1,
+         "country" : "US",
+         "date" : "1986",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "barcode" : "724349347823",
+         "asin" : "B000002UVZ",
+         "id" : "c82fe740-e65d-3a80-b477-0a9c29db6920",
+         "track-count" : 12,
+         "title" : "Lifes Rich Pageant",
+         "release-events" : [
+            {
+               "area" : {
+                  "name" : "United States",
+                  "iso-3166-1-codes" : [
+                     "US"
+                  ],
+                  "id" : "489ce91b-6658-3307-9877-795b68554c98",
+                  "sort-name" : "United States"
+               },
+               "date" : "1986"
+            }
+         ],
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "name" : "R.E.M.",
+                  "sort-name" : "R.E.M.",
+                  "disambiguation" : "Athens, US rock band"
+               }
+            }
+         ]
+      },
+      {
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M.",
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+               }
+            }
+         ],
+         "release-events" : [
+            {
+               "area" : {
+                  "id" : "489ce91b-6658-3307-9877-795b68554c98",
+                  "name" : "United States",
+                  "iso-3166-1-codes" : [
+                     "US"
+                  ],
+                  "sort-name" : "United States"
+               },
+               "date" : "1986-07-29"
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "track-count" : 12,
+         "id" : "4d48bb71-f111-3249-b13b-e08ce832e830",
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "barcode" : "",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "date" : "1986-07-29",
+         "country" : "US",
+         "count" : 1,
+         "release-group" : {
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant",
+            "primary-type" : "Album",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939"
+         },
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "packaging" : "Jewel Case",
+         "label-info" : [
+            {
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               },
+               "catalog-number" : "IRSD-5783"
+            },
+            {
+               "label" : {
+                  "name" : "MCA Records",
+                  "id" : "46a3941a-c810-47a1-974f-955effec4d09"
+               },
+               "catalog-number" : "JVC-522"
+            }
+         ],
+         "media" : [
+            {
+               "format" : "CD",
+               "track-count" : 12,
+               "disc-count" : 13
+            }
+         ],
+         "status" : "Official",
+         "disambiguation" : "disc: monochrome with JVC-522 or IRSD-5783",
+         "score" : 100
+      },
+      {
+         "score" : 100,
+         "status" : "Official",
+         "label-info" : [
+            {
+               "catalog-number" : "IRLD 19080",
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               }
+            }
+         ],
+         "media" : [
+            {
+               "disc-count" : 14,
+               "track-count" : 12,
+               "format" : "CD"
+            }
+         ],
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "packaging" : "Jewel Case",
+         "release-group" : {
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant",
+            "primary-type" : "Album"
+         },
+         "count" : 1,
+         "country" : "GB",
+         "date" : "1986-07-28",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "barcode" : "008811908027",
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "asin" : "B00004SE3N",
+         "id" : "f500ae63-dc60-3584-aa6d-854d2656d994",
+         "title" : "Lifes Rich Pageant",
+         "release-events" : [
+            {
+               "date" : "1986-07-28",
+               "area" : {
+                  "iso-3166-1-codes" : [
+                     "GB"
+                  ],
+                  "name" : "United Kingdom",
+                  "id" : "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
+                  "sort-name" : "United Kingdom"
+               }
+            }
+         ],
+         "track-count" : 12,
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M."
+               },
+               "name" : "R.E.M."
+            }
+         ]
+      },
+      {
+         "score" : 100,
+         "status" : "Official",
+         "media" : [
+            {
+               "disc-count" : 2,
+               "track-count" : 12,
+               "format" : "CD"
+            }
+         ],
+         "label-info" : [
+            {
+               "catalog-number" : "JVC-522",
+               "label" : {
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03",
+                  "name" : "I.R.S. Records"
+               }
+            }
+         ],
+         "packaging" : "Jewel Case",
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "release-group" : {
+            "primary-type" : "Album",
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939"
+         },
+         "count" : 1,
+         "country" : "CA",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "date" : "",
+         "barcode" : "076732578322",
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "id" : "56564532-2ddc-4575-af04-e076cd565610",
+         "track-count" : 12,
+         "release-events" : [
+            {
+               "date" : "",
+               "area" : {
+                  "sort-name" : "Canada",
+                  "id" : "71bbafaa-e825-3e15-8ca9-017dcad1748b",
+                  "name" : "Canada",
+                  "iso-3166-1-codes" : [
+                     "CA"
+                  ]
+               }
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "name" : "R.E.M.",
+                  "sort-name" : "R.E.M.",
+                  "disambiguation" : "Athens, US rock band"
+               },
+               "name" : "R.E.M."
+            }
+         ]
+      },
+      {
+         "track-count" : 12,
+         "title" : "Lifes Rich Pageant",
+         "release-events" : [
+            {
+               "date" : "1986",
+               "area" : {
+                  "sort-name" : "United States",
+                  "iso-3166-1-codes" : [
+                     "US"
+                  ],
+                  "name" : "United States",
+                  "id" : "489ce91b-6658-3307-9877-795b68554c98"
+               }
+            }
+         ],
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "sort-name" : "R.E.M.",
+                  "disambiguation" : "Athens, US rock band",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "name" : "R.E.M."
+               },
+               "name" : "R.E.M."
+            }
+         ],
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "id" : "4ced616f-832a-499e-a1ff-c89857b34e82",
+         "barcode" : "",
+         "country" : "US",
+         "date" : "1986",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "packaging" : "Jewel Case",
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "count" : 1,
+         "release-group" : {
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant",
+            "primary-type" : "Album",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc"
+         },
+         "media" : [
+            {
+               "format" : "CD",
+               "disc-count" : 1,
+               "track-count" : 12
+            }
+         ],
+         "label-info" : [
+            {
+               "catalog-number" : "IRSD-5783",
+               "label" : {
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03",
+                  "name" : "I.R.S. Records"
+               }
+            },
+            {
+               "catalog-number" : "JVC-522"
+            }
+         ],
+         "disambiguation" : "made in Japan",
+         "status" : "Official",
+         "score" : 100
+      },
+      {
+         "release-events" : [
+            {
+               "area" : {
+                  "iso-3166-1-codes" : [
+                     "US"
+                  ],
+                  "name" : "United States",
+                  "id" : "489ce91b-6658-3307-9877-795b68554c98",
+                  "sort-name" : "United States"
+               },
+               "date" : "1986-07-29"
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "track-count" : 12,
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M."
+               }
+            }
+         ],
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "id" : "41189c82-d75e-423f-a669-c766cccdd5f8",
+         "asin" : "B000002O2Y",
+         "barcode" : "076732578322",
+         "country" : "US",
+         "date" : "1986-07-29",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "packaging" : "Jewel Case",
+         "release-group" : {
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type" : "Album",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc"
+         },
+         "count" : 1,
+         "label-info" : [
+            {
+               "label" : {
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03",
+                  "name" : "I.R.S. Records"
+               },
+               "catalog-number" : "IRSD-5783"
+            },
+            {
+               "catalog-number" : "JVC-522"
+            }
+         ],
+         "media" : [
+            {
+               "format" : "CD",
+               "track-count" : 12,
+               "disc-count" : 0
+            }
+         ],
+         "status" : "Official",
+         "score" : 100
+      },
+      {
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M.",
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+               },
+               "name" : "R.E.M."
+            }
+         ],
+         "track-count" : 31,
+         "release-events" : [
+            {
+               "date" : "2011-07-11",
+               "area" : {
+                  "id" : "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
+                  "name" : "United Kingdom",
+                  "iso-3166-1-codes" : [
+                     "GB"
+                  ],
+                  "sort-name" : "United Kingdom"
+               }
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "id" : "241d4b00-ed4b-4bda-9a55-e38a08880628",
+         "asin" : "B004YTGRMI",
+         "packaging-id" : "815b7785-8284-3926-8f04-e48bc6c4d102",
+         "barcode" : "5099908244727",
+         "text-representation" : {
+            "language" : "eng",
+            "script" : "Latn"
+         },
+         "date" : "2011-07-11",
+         "country" : "GB",
+         "release-group" : {
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type" : "Album",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant"
+         },
+         "count" : 2,
+         "packaging" : "Other",
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "media" : [
+            {
+               "disc-count" : 1,
+               "track-count" : 12,
+               "format" : "CD"
+            },
+            {
+               "format" : "CD",
+               "disc-count" : 1,
+               "track-count" : 19
+            }
+         ],
+         "label-info" : [
+            {
+               "catalog-number" : "5099908244727",
+               "label" : {
+                  "name" : "Capitol Records",
+                  "id" : "abea2d3e-eabf-4480-ab24-9382dd642c73"
+               }
+            },
+            {
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               }
+            }
+         ],
+         "status" : "Official",
+         "disambiguation" : "25th anniversary edition",
+         "score" : 100
+      },
+      {
+         "score" : 100,
+         "status" : "Official",
+         "label-info" : [
+            {
+               "catalog-number" : "IRLD 19080",
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               }
+            }
+         ],
+         "media" : [
+            {
+               "format" : "CD",
+               "track-count" : 18,
+               "disc-count" : 1
+            }
+         ],
+         "release-group" : {
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type" : "Album",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant"
+         },
+         "count" : 1,
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "packaging" : "Jewel Case",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "date" : "1986",
+         "country" : "GB",
+         "barcode" : "008811908027",
+         "id" : "1249abaf-29b6-48e2-9095-b64f7b15e200",
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M.",
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+               }
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "release-events" : [
+            {
+               "date" : "1986",
+               "area" : {
+                  "sort-name" : "United Kingdom",
+                  "id" : "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
+                  "name" : "United Kingdom",
+                  "iso-3166-1-codes" : [
+                     "GB"
+                  ]
+               }
+            }
+         ],
+         "track-count" : 18
+      },
+      {
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "id" : "95af5680-503e-49cc-b035-b8cf9f1e2ab2",
+         "track-count" : 12,
+         "title" : "Lifes Rich Pageant",
+         "release-events" : [
+            {
+               "date" : "1986",
+               "area" : {
+                  "sort-name" : "United Kingdom",
+                  "id" : "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
+                  "name" : "United Kingdom",
+                  "iso-3166-1-codes" : [
+                     "GB"
+                  ]
+               }
+            }
+         ],
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M.",
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+               },
+               "name" : "R.E.M."
+            }
+         ],
+         "country" : "GB",
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "date" : "1986",
+         "barcode" : "5013747101423",
+         "media" : [
+            {
+               "format" : "CD",
+               "disc-count" : 1,
+               "track-count" : 12
+            }
+         ],
+         "label-info" : [
+            {
+               "label" : {
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03",
+                  "name" : "I.R.S. Records"
+               },
+               "catalog-number" : "DMIRG1014"
+            }
+         ],
+         "packaging" : "Jewel Case",
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "release-group" : {
+            "primary-type" : "Album",
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939"
+         },
+         "count" : 1,
+         "score" : 100,
+         "status" : "Official"
+      },
+      {
+         "release-group" : {
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type" : "Album"
+         },
+         "count" : 1,
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "packaging" : "Box",
+         "label-info" : [
+            {
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               },
+               "catalog-number" : "465381 2"
+            }
+         ],
+         "media" : [
+            {
+               "format" : "CD",
+               "disc-count" : 1,
+               "track-count" : 12
+            }
+         ],
+         "status" : "Official",
+         "score" : 100,
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M.",
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+               },
+               "name" : "R.E.M."
+            }
+         ],
+         "release-events" : [
+            {
+               "date" : "1986",
+               "area" : {
+                  "sort-name" : "France",
+                  "id" : "08310658-51eb-3801-80de-5a0739207115",
+                  "iso-3166-1-codes" : [
+                     "FR"
+                  ],
+                  "name" : "France"
+               }
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "track-count" : 12,
+         "id" : "40cfd083-7991-4b39-b236-eb59b5e81d39",
+         "packaging-id" : "c1668fc7-8944-4a00-bc3e-46e8d861d211",
+         "barcode" : "5099746538125",
+         "date" : "1986",
+         "text-representation" : {
+            "language" : "eng",
+            "script" : "Latn"
+         },
+         "country" : "FR"
+      },
+      {
+         "label-info" : [
+            {
+               "catalog-number" : "IRSD-5783",
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               }
+            },
+            {
+               "catalog-number" : "D 100166",
+               "label" : {
+                  "name" : "BMG Direct Marketing, Inc.",
+                  "id" : "9a7d39a4-a887-40f3-a645-a9a136d1f13f"
+               }
+            }
+         ],
+         "media" : [
+            {
+               "format" : "CD",
+               "disc-count" : 1,
+               "track-count" : 12
+            }
+         ],
+         "release-group" : {
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type" : "Album",
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc"
+         },
+         "count" : 1,
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe",
+         "packaging" : "Jewel Case",
+         "score" : 100,
+         "status" : "Official",
+         "id" : "f95eac97-5750-4619-9860-a24819722005",
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "artist-credit" : [
+            {
+               "artist" : {
+                  "name" : "R.E.M.",
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation" : "Athens, US rock band",
+                  "sort-name" : "R.E.M."
+               },
+               "name" : "R.E.M."
+            }
+         ],
+         "release-events" : [
+            {
+               "date" : "1986",
+               "area" : {
+                  "id" : "489ce91b-6658-3307-9877-795b68554c98",
+                  "name" : "United States",
+                  "iso-3166-1-codes" : [
+                     "US"
+                  ],
+                  "sort-name" : "United States"
+               }
+            }
+         ],
+         "title" : "Lifes Rich Pageant",
+         "track-count" : 12,
+         "date" : "1986",
+         "text-representation" : {
+            "language" : "eng",
+            "script" : "Latn"
+         },
+         "country" : "US",
+         "barcode" : ""
+      },
+      {
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "date" : "1986",
+         "country" : "US",
+         "barcode" : "",
+         "id" : "a1c303ff-42d0-4373-b62a-bbe540295ac6",
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "name" : "R.E.M.",
+                  "sort-name" : "R.E.M.",
+                  "disambiguation" : "Athens, US rock band"
+               }
+            }
+         ],
+         "track-count" : 12,
+         "title" : "Lifes Rich Pageant",
+         "release-events" : [
+            {
+               "area" : {
+                  "id" : "489ce91b-6658-3307-9877-795b68554c98",
+                  "iso-3166-1-codes" : [
+                     "US"
+                  ],
+                  "name" : "United States",
+                  "sort-name" : "United States"
+               },
+               "date" : "1986"
+            }
+         ],
+         "score" : 100,
+         "status" : "Official",
+         "disambiguation" : "disc: green with IRSD-5783",
+         "media" : [
+            {
+               "format" : "CD",
+               "track-count" : 12,
+               "disc-count" : 0
+            }
+         ],
+         "label-info" : [
+            {
+               "catalog-number" : "IRSD-5783",
+               "label" : {
+                  "name" : "I.R.S. Records",
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03"
+               }
+            },
+            {
+               "catalog-number" : "JVC-522",
+               "label" : {
+                  "id" : "5aa5ddcd-b5d9-4bdf-b528-5083dfd98f03",
+                  "name" : "I.R.S. Records"
+               }
+            }
+         ],
+         "release-group" : {
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type" : "Album",
+            "title" : "Lifes Rich Pageant",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc"
+         },
+         "count" : 1,
+         "status-id" : "4e304316-386d-3409-af2e-78857eec5cfe"
+      },
+      {
+         "packaging-id" : "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+         "id" : "a2ecf435-b626-40a7-9798-52325807b3fc",
+         "track-count" : 31,
+         "title" : "Lifes Rich Pageant 25th Anniversary Edition",
+         "artist-credit" : [
+            {
+               "name" : "R.E.M.",
+               "artist" : {
+                  "id" : "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "name" : "R.E.M.",
+                  "sort-name" : "R.E.M.",
+                  "disambiguation" : "Athens, US rock band"
+               }
+            }
+         ],
+         "text-representation" : {
+            "script" : "Latn",
+            "language" : "eng"
+         },
+         "media" : [
+            {
+               "disc-count" : 0,
+               "track-count" : 12,
+               "format" : "CD"
+            },
+            {
+               "format" : "CD",
+               "disc-count" : 0,
+               "track-count" : 19
+            }
+         ],
+         "label-info" : [
+            {
+               "label" : {
+                  "id" : "d8ffc51c-e5d5-4e40-b8c0-8299b26d03cb",
+                  "name" : "EMI Music Catalogue Marketing"
+               },
+               "catalog-number" : "[none]"
+            }
+         ],
+         "packaging" : "Jewel Case",
+         "status-id" : "518ffc83-5cde-34df-8627-81bff5093d92",
+         "release-group" : {
+            "id" : "8b6b2628-7bd4-3fed-9d65-cf4e5dc45939",
+            "primary-type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "primary-type" : "Album",
+            "type-id" : "f529b476-6e62-324f-b0aa-1f3e33d313fc",
+            "title" : "Lifes Rich Pageant"
+         },
+         "count" : 2,
+         "score" : 95,
+         "status" : "Promotion"
+      }
+   ],
+   "created" : "2022-08-01T23:51:26.626Z",
+   "count" : 15
+}
+EOF
+$out = <<'EOF';
+1f233a68-c3c2-348b-a135-10edc450edf7 1993        18 tracks /  4 discs in XE Lifes Rich Pageant by I.R.S. Records; The I.R.S. Years Vintage 1986, Official
+c82fe740-e65d-3a80-b477-0a9c29db6920 1986        12 tracks / 13 discs in US Lifes Rich Pageant by I.R.S. Records; , Official
+4d48bb71-f111-3249-b13b-e08ce832e830 1986-07-29  12 tracks / 13 discs in US Lifes Rich Pageant by I.R.S. Records, MCA Records; disc: monochrome with JVC-522 or IRSD-5783, Official
+f500ae63-dc60-3584-aa6d-854d2656d994 1986-07-28  12 tracks / 14 discs in GB Lifes Rich Pageant by I.R.S. Records; , Official
+56564532-2ddc-4575-af04-e076cd565610             12 tracks /  2 discs in CA Lifes Rich Pageant by I.R.S. Records; , Official
+4ced616f-832a-499e-a1ff-c89857b34e82 1986        12 tracks /  1 discs in US Lifes Rich Pageant by I.R.S. Records, UNKNOWN; made in Japan, Official
+41189c82-d75e-423f-a669-c766cccdd5f8 1986-07-29  12 tracks /  0 discs in US Lifes Rich Pageant by I.R.S. Records, UNKNOWN; , Official
+241d4b00-ed4b-4bda-9a55-e38a08880628 2011-07-11  31 tracks /  2 discs in GB Lifes Rich Pageant by Capitol Records, I.R.S. Records; 25th anniversary edition, Official
+1249abaf-29b6-48e2-9095-b64f7b15e200 1986        18 tracks /  1 discs in GB Lifes Rich Pageant by I.R.S. Records; , Official
+95af5680-503e-49cc-b035-b8cf9f1e2ab2 1986        12 tracks /  1 discs in GB Lifes Rich Pageant by I.R.S. Records; , Official
+40cfd083-7991-4b39-b236-eb59b5e81d39 1986        12 tracks /  1 discs in FR Lifes Rich Pageant by I.R.S. Records; , Official
+f95eac97-5750-4619-9860-a24819722005 1986        12 tracks /  1 discs in US Lifes Rich Pageant by I.R.S. Records, BMG Direct Marketing, Inc.; , Official
+a1c303ff-42d0-4373-b62a-bbe540295ac6 1986        12 tracks /  0 discs in US Lifes Rich Pageant by I.R.S. Records, I.R.S. Records; disc: green with IRSD-5783, Official
+a2ecf435-b626-40a7-9798-52325807b3fc UNKNOWN     31 tracks /  0 discs in -- Lifes Rich Pageant 25th Anniversary Edition by EMI Music Catalogue Marketing; , Promotion
+EOF
+is list_releases(read_releases($in)) . "\n", $out;
+
+$in = <<'EOF';
+{
+  "quality": "normal",
+  "status-id": "4e304316-386d-3409-af2e-78857eec5cfe",
+  "country": "US",
+  "id": "4d48bb71-f111-3249-b13b-e08ce832e830",
+  "media": [
+    {
+      "position": 1,
+      "format-id": "9712d52a-4509-3d4b-a1a2-67c88c643e31",
+      "track-count": 12,
+      "title": "",
+      "track-offset": 0,
+      "format": "CD",
+      "tracks": [
+        {
+          "position": 1,
+          "title": "unicode test: ’",
+          "recording": {
+            "video": false,
+            "title": "Begin the Begin",
+            "length": 208600,
+            "first-release-date": "1986-07-28",
+            "artist-credit": [
+              {
+                "joinphrase": "",
+                "name": "R.E.M.",
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "name": "R.E.M.",
+                  "sort-name": "R.E.M.",
+                  "type": "Group"
+                }
+              }
+            ],
+            "disambiguation": "",
+            "id": "ef7bc67f-1072-4798-8145-c4fff10fce47"
+          },
+          "number": "1",
+          "length": 208600,
+          "artist-credit": [
+            {
+              "name": "R.E.M.",
+              "joinphrase": "",
+              "artist": {
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "disambiguation": "Athens, US rock band",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "name": "R.E.M.",
+                "type": "Group",
+                "sort-name": "R.E.M."
+              }
+            }
+          ],
+          "id": "c8b2c668-fa35-3109-9626-028f5485fa86"
+        },
+        {
+          "id": "c7dee404-95c7-320b-b935-da89cbf2b22d",
+          "artist-credit": [
+            {
+              "name": "R.E.M.",
+              "joinphrase": "",
+              "artist": {
+                "name": "R.E.M.",
+                "sort-name": "R.E.M.",
+                "type": "Group",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band"
+              }
+            }
+          ],
+          "length": 204773,
+          "number": "2",
+          "recording": {
+            "artist-credit": [
+              {
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation": "Athens, US rock band",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "name": "R.E.M.",
+                  "type": "Group",
+                  "sort-name": "R.E.M."
+                },
+                "joinphrase": "",
+                "name": "R.E.M."
+              }
+            ],
+            "disambiguation": "",
+            "id": "b02f5e17-f53b-494b-b383-510ab0b4f837",
+            "video": false,
+            "title": "These Days",
+            "length": 204773,
+            "first-release-date": "1986-07-28"
+          },
+          "title": "These Days",
+          "position": 2
+        },
+        {
+          "id": "40168d2a-6efc-3600-a27c-2ce298a52845",
+          "artist-credit": [
+            {
+              "joinphrase": "",
+              "name": "R.E.M.",
+              "artist": {
+                "type": "Group",
+                "sort-name": "R.E.M.",
+                "name": "R.E.M.",
+                "disambiguation": "Athens, US rock band",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+              }
+            }
+          ],
+          "length": 170800,
+          "number": "3",
+          "recording": {
+            "id": "9d34a6df-d6fb-45f9-b433-cd55979acc2b",
+            "disambiguation": "",
+            "artist-credit": [
+              {
+                "joinphrase": "",
+                "name": "R.E.M.",
+                "artist": {
+                  "sort-name": "R.E.M.",
+                  "type": "Group",
+                  "name": "R.E.M.",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+                }
+              }
+            ],
+            "first-release-date": "1986-07-14",
+            "length": 171000,
+            "title": "Fall on Me",
+            "video": false
+          },
+          "title": "Fall on Me",
+          "position": 3
+        },
+        {
+          "id": "381cacd5-ef2c-3a29-90fa-5920ae00ca82",
+          "artist-credit": [
+            {
+              "artist": {
+                "type": "Group",
+                "sort-name": "R.E.M.",
+                "name": "R.E.M.",
+                "disambiguation": "Athens, US rock band",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+              },
+              "name": "R.E.M.",
+              "joinphrase": ""
+            }
+          ],
+          "number": "4",
+          "length": 261426,
+          "position": 4,
+          "recording": {
+            "id": "776f199b-1d8b-43b4-9c71-d5ce2836ba4f",
+            "artist-credit": [
+              {
+                "name": "R.E.M.",
+                "joinphrase": "",
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation": "Athens, US rock band",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "name": "R.E.M.",
+                  "type": "Group",
+                  "sort-name": "R.E.M."
+                }
+              }
+            ],
+            "disambiguation": "",
+            "length": 261426,
+            "first-release-date": "1986-07-28",
+            "title": "Cuyahoga",
+            "video": false
+          },
+          "title": "Cuyahoga"
+        },
+        {
+          "length": 171333,
+          "number": "5",
+          "title": "Hyena",
+          "recording": {
+            "id": "e0fe4823-0b09-4cd9-98e1-c3072f05aad9",
+            "artist-credit": [
+              {
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "name": "R.E.M.",
+                  "sort-name": "R.E.M.",
+                  "type": "Group"
+                },
+                "joinphrase": "",
+                "name": "R.E.M."
+              }
+            ],
+            "disambiguation": "",
+            "length": 171333,
+            "first-release-date": "1986-07-28",
+            "title": "Hyena",
+            "video": false
+          },
+          "position": 5,
+          "id": "4123f0ca-05c9-367c-b93c-614446b0ac32",
+          "artist-credit": [
+            {
+              "artist": {
+                "disambiguation": "Athens, US rock band",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "type": "Group",
+                "sort-name": "R.E.M.",
+                "name": "R.E.M."
+              },
+              "joinphrase": "",
+              "name": "R.E.M."
+            }
+          ]
+        },
+        {
+          "number": "6",
+          "length": 87573,
+          "position": 6,
+          "title": "Underneath the Bunker",
+          "recording": {
+            "length": 87573,
+            "first-release-date": "1986-07-28",
+            "video": false,
+            "title": "Underneath the Bunker",
+            "id": "71ba5984-39be-40a3-a364-c3333aab8893",
+            "artist-credit": [
+              {
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation": "Athens, US rock band",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "name": "R.E.M.",
+                  "type": "Group",
+                  "sort-name": "R.E.M."
+                },
+                "name": "R.E.M.",
+                "joinphrase": ""
+              }
+            ],
+            "disambiguation": ""
+          },
+          "id": "a9a8b965-be67-3bbd-b8cd-b4480efb5ca8",
+          "artist-credit": [
+            {
+              "artist": {
+                "sort-name": "R.E.M.",
+                "type": "Group",
+                "name": "R.E.M.",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+              },
+              "name": "R.E.M.",
+              "joinphrase": ""
+            }
+          ]
+        },
+        {
+          "number": "7",
+          "length": 237000,
+          "position": 7,
+          "title": "The Flowers of Guatemala",
+          "recording": {
+            "video": false,
+            "title": "The Flowers of Guatemala",
+            "length": 237000,
+            "first-release-date": "1986-07-28",
+            "artist-credit": [
+              {
+                "artist": {
+                  "name": "R.E.M.",
+                  "type": "Group",
+                  "sort-name": "R.E.M.",
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "disambiguation": "Athens, US rock band",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b"
+                },
+                "joinphrase": "",
+                "name": "R.E.M."
+              }
+            ],
+            "disambiguation": "",
+            "id": "6f22dbbd-daa8-4dcb-a8f0-c4f099c10210"
+          },
+          "id": "6e55746c-5778-3dd1-a3be-b9923c8fb17c",
+          "artist-credit": [
+            {
+              "joinphrase": "",
+              "name": "R.E.M.",
+              "artist": {
+                "name": "R.E.M.",
+                "sort-name": "R.E.M.",
+                "type": "Group",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band"
+              }
+            }
+          ]
+        },
+        {
+          "length": 230466,
+          "number": "8",
+          "title": "I Believe",
+          "recording": {
+            "artist-credit": [
+              {
+                "artist": {
+                  "type": "Group",
+                  "sort-name": "R.E.M.",
+                  "name": "R.E.M.",
+                  "disambiguation": "Athens, US rock band",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+                },
+                "joinphrase": "",
+                "name": "R.E.M."
+              }
+            ],
+            "disambiguation": "",
+            "id": "2f07435f-3f64-4ca3-9596-4adaeaf38ade",
+            "video": false,
+            "title": "I Believe",
+            "length": 230466,
+            "first-release-date": "1986-07-28"
+          },
+          "position": 8,
+          "id": "43bb2989-be7d-3199-91c8-4220c4f3f926",
+          "artist-credit": [
+            {
+              "joinphrase": "",
+              "name": "R.E.M.",
+              "artist": {
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "sort-name": "R.E.M.",
+                "type": "Group",
+                "name": "R.E.M."
+              }
+            }
+          ]
+        },
+        {
+          "length": 214760,
+          "number": "9",
+          "recording": {
+            "length": 214760,
+            "first-release-date": "1986-07-28",
+            "video": false,
+            "title": "What If We Give It Away?",
+            "id": "1a4b19a2-8d7b-456c-8eb4-058a6bd66e11",
+            "artist-credit": [
+              {
+                "name": "R.E.M.",
+                "joinphrase": "",
+                "artist": {
+                  "sort-name": "R.E.M.",
+                  "type": "Group",
+                  "name": "R.E.M.",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+                }
+              }
+            ],
+            "disambiguation": ""
+          },
+          "title": "What If We Give It Away?",
+          "position": 9,
+          "id": "41ee8f0a-a262-3b70-a38c-be66ff41b9e4",
+          "artist-credit": [
+            {
+              "name": "R.E.M.",
+              "joinphrase": "",
+              "artist": {
+                "name": "R.E.M.",
+                "sort-name": "R.E.M.",
+                "type": "Group",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band"
+              }
+            }
+          ]
+        },
+        {
+          "artist-credit": [
+            {
+              "artist": {
+                "sort-name": "R.E.M.",
+                "type": "Group",
+                "name": "R.E.M.",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+              },
+              "name": "R.E.M.",
+              "joinphrase": ""
+            }
+          ],
+          "id": "023c2798-503d-3279-b7fb-e11e0747358d",
+          "position": 10,
+          "recording": {
+            "id": "bcef48f3-92bb-43d5-86af-245b8ccfcf67",
+            "artist-credit": [
+              {
+                "name": "R.E.M.",
+                "joinphrase": "",
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "name": "R.E.M.",
+                  "sort-name": "R.E.M.",
+                  "type": "Group"
+                }
+              }
+            ],
+            "disambiguation": "",
+            "first-release-date": "1986-07-28",
+            "length": 180866,
+            "video": false,
+            "title": "Just a Touch"
+          },
+          "title": "Just a Touch",
+          "number": "10",
+          "length": 180866
+        },
+        {
+          "length": 170133,
+          "number": "11",
+          "recording": {
+            "length": 170133,
+            "first-release-date": "1986-07-28",
+            "video": false,
+            "title": "Swan Swan H",
+            "id": "f43fd53b-a00f-493a-9565-0e845ded0318",
+            "artist-credit": [
+              {
+                "joinphrase": "",
+                "name": "R.E.M.",
+                "artist": {
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "name": "R.E.M.",
+                  "sort-name": "R.E.M.",
+                  "type": "Group"
+                }
+              }
+            ],
+            "disambiguation": ""
+          },
+          "title": "Swan Swan H",
+          "position": 11,
+          "id": "bc87efe6-3ee2-3132-a5c3-023d43b70718",
+          "artist-credit": [
+            {
+              "name": "R.E.M.",
+              "joinphrase": "",
+              "artist": {
+                "name": "R.E.M.",
+                "type": "Group",
+                "sort-name": "R.E.M.",
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "disambiguation": "Athens, US rock band",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b"
+              }
+            }
+          ]
+        },
+        {
+          "position": 12,
+          "title": "Superman",
+          "recording": {
+            "length": 173133,
+            "first-release-date": "1986-03-09",
+            "title": "Superman",
+            "video": false,
+            "id": "fed683e6-f707-430d-9824-f1df1d586fab",
+            "disambiguation": "",
+            "artist-credit": [
+              {
+                "joinphrase": "",
+                "name": "R.E.M.",
+                "artist": {
+                  "sort-name": "R.E.M.",
+                  "type": "Group",
+                  "name": "R.E.M.",
+                  "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                  "disambiguation": "Athens, US rock band",
+                  "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58"
+                }
+              }
+            ]
+          },
+          "number": "12",
+          "length": 173133,
+          "artist-credit": [
+            {
+              "joinphrase": "",
+              "name": "R.E.M.",
+              "artist": {
+                "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+                "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b",
+                "disambiguation": "Athens, US rock band",
+                "name": "R.E.M.",
+                "sort-name": "R.E.M.",
+                "type": "Group"
+              }
+            }
+          ],
+          "id": "7269b198-bb1a-3cf8-a3e9-27b36af8d246"
+        }
+      ]
+    }
+  ],
+  "artist-credit": [
+    {
+      "name": "R.E.M.",
+      "joinphrase": "",
+      "artist": {
+        "name": "R.E.M.",
+        "type": "Group",
+        "sort-name": "R.E.M.",
+        "id": "ea4dfa26-f633-4da6-a52a-f49ea4897b58",
+        "disambiguation": "Athens, US rock band",
+        "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b"
+      }
+    }
+  ],
+  "status": "Official",
+  "packaging-id": "ec27701a-4a22-37f4-bfac-6616e0f9750a",
+  "barcode": "",
+  "cover-art-archive": {
+    "artwork": true,
+    "back": true,
+    "count": 5,
+    "darkened": false,
+    "front": true
+  },
+  "title": "Lifes Rich Pageant",
+  "date": "1986-07-29",
+  "release-events": [
+    {
+      "date": "1986-07-29",
+      "area": {
+        "id": "489ce91b-6658-3307-9877-795b68554c98",
+        "iso-3166-1-codes": [
+          "US"
+        ],
+        "disambiguation": "",
+        "type-id": null,
+        "name": "United States",
+        "type": null,
+        "sort-name": "United States"
+      }
+    }
+  ],
+  "text-representation": {
+    "script": "Latn",
+    "language": "eng"
+  },
+  "packaging": "Jewel Case",
+  "disambiguation": "disc: monochrome with JVC-522 or IRSD-5783",
+  "asin": null
+}
+EOF
+$out = <<'EOF';
+ARTIST=R.E.M.
+ALBUM=Lifes Rich Pageant
+DATE=1986-07-29
+TITLE[1]=unicode test: '
+TITLE[2]=These Days
+TITLE[3]=Fall on Me
+TITLE[4]=Cuyahoga
+TITLE[5]=Hyena
+TITLE[6]=Underneath the Bunker
+TITLE[7]=The Flowers of Guatemala
+TITLE[8]=I Believe
+TITLE[9]=What If We Give It Away?
+TITLE[10]=Just a Touch
+TITLE[11]=Swan Swan H
+TITLE[12]=Superman
+EOF
+is format_tags(release => read_release($in)) . "\n", $out;