BOM.pl

silent11 on 2004-08-30T13:53:58

#!/usr/bin/perl

use strict; use LWP::Simple; use HTML::TokeParser;

# usage Links("URL","File Extension","Save Files to"); # This will download the Book of Mormon in MP3 format.

Links("http://lds.org/mp3/display/0,18692,5297-41,00.html", "mp3" , "./BofM/");

sub Links { my $count = 0; my $url = shift; my $type = shift; my $dir = shift; if ( defined $dir ) { # mkdir $dir || die $!; print "$dir directory was created\n"; } print "URL : $url \n TYPE: $type \n\n"; unless ( defined $url ) { return("No URL Provided\n"); die $!; } unless ( defined $type ) { return("No Link Type Provided\n"); die $!; } my $html = get( $url ); my $page = HTML::TokeParser->new(\$html);

while ( my $token = $page->get_tag("a")) { my $url = $token->[1]{href} || "-"; my $file = $url; $file =~ s/^.+\///;

if ($url =~ /$type$/i) { print "Getting $url as $file \n\n"; sleep 3; getstore( $url , $dir . '/' . $file ) || die $!; $count ++; } } }