Friday, 14 September 2018

Perl to download mp3 from the html page using wget

The script I have tried to get the mp3 files from the web.

#!/usr/bin/perl

die "Usage: $0 <url of page> \n" if @ARGV < 1;

sub getLineFromFile
{
my @outArray;
my $in = shift;
open (my $inf,"<",$in) or die "can't reader the $in";
while(my $row = <$inf>)
{
chomp $row;
#print $row."\n";
push (@outArray,$row);

return @outArray;
}

my $url = shift;
`wget $url`;

$url =~ /([^\/]+\.html)/; #Regex to look for last / and token next with .html 
my$filename = $1;

my @lines = getLineFromFile($filename);

foreach my $line (@lines)
{
my $command;
$line =~/<a .*href="(.*download.*\.mp3)">/; #modify if you find any different href url
my $mp3url = $1;
if($mp3url =~ /\.mp3$/){
#print "get me ".$mp3url."\n";
`wget $mp3url`;

}
}
unlink $filename;


hope it helps and save your time 👍

No comments:

Post a Comment