-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlmanager2.pl
94 lines (80 loc) · 1.64 KB
/
dlmanager2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/perl
use warnings;
use Term::ANSIColor qw(:constants);
my @list;
my @done;
my @failed;
my @editors;
my $failure;
my $file;
my $filename;
sub getfile;
@editors = (q{nano},q{vim},q{vi});
$file = "/tmp/dlmanagerList";
foreach(@editors)
{
if (system(qq{$_ $file 2>/dev/null}) == 0)
{
last;
}
}
open(FILE, "<", $file) or die "Could not open $file: $!\n";
@list = <FILE>;
close(FILE);
foreach( @list )
{
$failure = 0;
$_ =~ s/^http:/https:/;
if( getfile( $_ ) == 1 ){
print RED, qq{FAILED, trying unsecure mode (http)...\n}, RESET;
$_ =~ s/^https/http/;
$failure = 1;
}
if( $failure == 1 )
{
if( getfile( $_ ) == 1 )
{
print RED, qq{FAILED\n}, RESET;
push @failed, $filename;
}
}
}
print "\n\nTelechargements effectues:\n###----------------------###\n";
foreach( @done )
{
print $_,qq{\n};
}
print "###------------------------------------------------------------------###\n\n";
print "Telechargements echoues:\n###----------------------###\n";
foreach( @failed )
{
print $_,qq{\n};
}
print "###------------------------------------------------------------------###\n\n";
unlink( "$file" );
sub getfile
{
( $line ) = @_;
$line =~ s/\n//g;
$line =~ s/\s+$//g;
if( !$line )
{
return 0;
}
( $filename ) = $line =~ m|([^/]+)/?$|;
$filename =~ s/%20/ /g;
$filename =~ s/%5B/[/g;
$filename =~ s/%5D/]/g;
print qq{Getting $filename:};
if (system("wget -c -q --no-check-certificate $line") == 0)
{
print GREEN, qq{OK\n}, RESET;
push @done, $filename;
return 0;
}
else
{
return 1;
}
}
__END__