Ed2k Monitor
I shared /media/public/Incoming/waitinglist/ folder, so from other computers in the network user can create a text file with content of
ed2k:xxxxxxxxxxxxxxxxxxxThis script will monitor this folder for any new text file and feed ed2k links into aMule:
ed2k:xxxxxxxxxxxxxxxxx
#!/usr/bin/perl
#The purpose of this script is to monitor a directory periodically, and run ed2k (aMule) for new entries in this folder (then delete them).
#ben@fadshop.net. Jun 1, 2009.
# Version 2: Aug 11, 2009. Read each line of the files for importing.
# Edit Cronjob by:
# crontab -e
#0,15,30 * * * * script.sh
###or
#0-59/15 * * * * script.sh
# model: http://www.perlmonks.org/?node_id=283849
use strict;
use warnings;
sub printlog
{
my $logfile = shift;
my $logmessage = shift;
my $now = localtime time;
open(LOGFILE, ">>$logfile");
print LOGFILE $now . " " .$logmessage . "\n";
close LOGFILE;
}
sub scandir
{
my $dir = shift;
my $fileProcessor = shift;
opendir (DIR, $dir) or die "Cannot open $dir: $!\n";
while (my $filename = readdir(DIR))
{
next if $filename =~ /^\.\.?$/; # skip . and ..
if ($filename =~ /\.txt$/) {
&$fileProcessor("$dir/$filename");
}
if ($filename =~ /.torrent$/) {
`transmission "$filename"&`;
}
}
close DIR;
}
sub runed2k
{
my $filename = shift;
print "got file: $filename\n";
open(ED2KFILE, $filename);
foreach my $line (){
$line =~ s/\r(\n?)//;
if ($line =~ /^ed2k/){
`ed2k "$line"`;
#print LOG
printlog('/tmp/ed2klog', $line);
}
if ($line =~ /^http/){
chdir('/media/public/Incoming/');
`wget "$line"&`;
#print LOG
printlog('/tmp/ed2klog', $line);
}
}
close(ED2KFILE);
unlink($filename);
}
scandir('/media/public/Incoming/waitinglist',\&runed2k);
The result is: In any computer of my network, I can put the ed2k link into text file. The Linux server will retrieve the ed2k resource for me overnight.
0 Comments:
<< Home