export-images.pl

From Organic Design wiki
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.
#!/usr/bin/perl
use HTTP::Request;
use LWP::UserAgent;

$client = LWP::UserAgent->new(
	cookie_jar => {},
	agent      => 'Mozilla/5.0',
	from       => 'export-images.pl@organicdesign.co.nz',
	timeout    => 10,
);

$wiki = $ARGV[0];

$dir = $wiki =~ /(https?:\/\/(.+?))\// ? $2 : die "Please supply long form wiki URL";
$base = $1;
$content = $client->get("$wiki?title=Special:Imagelist&limit=500")->content;
@files = $content =~ /href\s*=\s*['"](\/[^"']+?\/.\/..\/[^'"]+?)["']/g;

mkdir $dir;
for $url (@files) {
	$file = $url =~ /.+\/(.+?)$/ ? $1 : die "Bad name ($url)";
	print "$file\n";
	open FH, '>', "$dir/$file";
	binmode FH;
	print FH $client->get("$base$url")->content;
	close FH;
}