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
|
#!/usr/bin/perl
# Submit an eDonkey download request to mldonkey
#
# Argument(s): An ed2k URI of the form:
#
# ed2k://|file|<filename>|<filesize>|<MD4-sum|
#
use LWP::UserAgent;
($#ARGV >= 0) || die "Usage: mldonkey_submit <ed2kURI> ...\n";
#
# Get username and password for mldonkey's HTTP GUI from
# /etc/sysconfig/donkey
#
# This file should read as follows:
#
# HTTPURL=http://localhost:4080
# HTTPUSER=me
# HTTPPASS=mypassword
#
$vars{'HTTPURL'} = "http://localhost:4080";
my $cfg = "/etc/sysconfig/mldonkey_submit";
open(I,"<$cfg") || die "Can't read $cfg: $!\n";
chomp (my @lines = (<I>));
close I;
foreach (@lines) {
next if (/^#/);
if (/([^=\s]+)=([^=\s]+)/) {
$vars{$1}="$2";
}
}
#
# If you don't like the above config file, you can hardcode
# user an password here and comment-out the above code.
# Do NOT comment out the default preset for $vars{'HTTPURL'}
#
#$vars{'HTTPURL'} = "http://localhost:4080";
#$vars{'HTTPUSER'} = "me";
#$vars{'HTTPPASS'} = "mypassword";
#
my $ua = LWP::UserAgent->new;
while (my $uri = shift @ARGV) {
$_ = URI::Escape::uri_unescape($uri);
if (/^ed2k:\/\/\|file\|[^|]+\|(\d+)\|([\dabcdefABCDEF]+)\|/) {
my $size = $1;
my $md4 = $2;
my $req = HTTP::Request->new(
GET => "$vars{'HTTPURL'}/submit?q=dd+$size+$md4"
);
if (($vars{'HTTPUSER'}) && ($vars{'HTTPPASS'})) {
$req->authorization_basic($vars{'HTTPUSER'},
$vars{'HTTPPASS'});
}
my $response = $ua->request($req);
if (!($response->is_success)) {
print $response->error_as_HTML;
exit 1;
}
} else {
print "Not an ed2k URI: $_\n";
}
}
|