Files
scripts/Perl Browse Links/get_links.pl
2024-10-14 00:08:40 +02:00

85 lines
1.3 KiB
Perl

#!/usr/bin/perl
use LWP::Simple;
open FILE, "<links_todo";
@LINKS=<FILE>;
close FILE;
open DONT, "<links_done";
@DONE=<DONT>;
close DONT;
print "\nExtrahiere Links\n\n";
foreach $link (@LINKS) {
chomp $link;
next if already_done("$link",@DONE);
next if ($link eq "");
$html = get ($link);
$html =~ m{<TITLE>(.*?)</TITLE>}gism;
$title = $1;
chomp $title;
print "Link: $link\nVerzeichnisnamen eingeben [xxx | \"$1\"]: ";
$path = <STDIN>;
chomp $path;
$path = $title if ($path eq "");
if ($path ne "xxx") {
print "Pfad '$path' wird erstellt\n";
mkdir ($path);
open_default_browser("$link");
open DONE, ">>links_done";
printf DONE "$link\n";
close DONE;
print "\n";
}
else {
print "Abbruch\n";
exit 0;
}
}
print "Ende\n\n";
sub already_done {
$link = shift;
foreach (@DONE) {
chomp;
if ($_ eq $link) {
return 1;
}
}
return 0;
}
sub open_default_browser {
my $url = shift;
my $platform = $^O;
my $cmd;
if ($platform eq 'darwin') { $cmd = "open \"$url\""; } # Mac OS X
elsif ($platform eq 'linux') { $cmd = "x-www-browser \"$url\""; } # Linux
elsif ($platform eq 'MSWin32') { $cmd = "start $url"; } # Win95..Win7
if (defined $cmd) {
qx /$cmd 2>&1/;
} else {
die "Can't locate default browser";
}
}