#!/usr/bin/perl

use warnings;
use strict;

while(<>) {
    if (m{(http://musicbrainz.org/show/release/\?releaseid=\d+)}) {
        open IN, "-|", "wget", "-O", "-", $1;
        while (my $line = <IN>) {
            if ($line =~ m{"/release/([a-z0-9-]*)\.html".*>(.*)<}) {
                my ($link, $title) = ($1, $2);
                $title =~ s/&#39;/'/g;
                s{http://musicbrainz.org/show/release/\?releaseid=\d+}{[wiki:Release:$link $title]};
                last;
            }
        }
        close IN;
        sleep 10 + rand(5);
    }
    print;
}
