How to Grab Media off the Internet
You're familiar with the streaming media, right? It's the same as a download. Indeed, one can actually capture the stuff in its native format. After the flip, I've included perl code to do just that! For those too lazy to cut and paste, it's at the usual place as well.
use LWP::Simple;
use HTML::TreeBuilder;
use File::Temp;
foreach my $page (@ARGV) {
my $pagedata = get $page;
my $tree = HTML::TreeBuilder->new;
$tree->parse($pagedata);
$tree->eof;
my @base = $tree->find('base');
my $base_url = '';
$base_url = $base[0]->{'href'} if @base;
my @embeds = $tree->find('embed');
foreach my $embed (@embeds) {
my $target = $embed->{'src'};
my $newurl = "$base_url$target";
my @newurl_parts = split (/\//);
my $filename = $newurl_parts[-1];
my ($fh, $fname) = tempfile("$filename");
print $fh get $newurl;
close $fh;
print STDERR "$filename saved as $fname";
}
$tree->delete;
}
