Ещё чуток поковырял patcher.pl...поправил пару ошибок и сделал чтобы в начало ini файла вставлялась секция [description] т.к. Config::IniFiles->new почему-то стал ругатся на то что файл ini начинается не с секции, а с каментов, вобщем вот такое в итоге получилось:
#!/usr/bin/perl
$cur_dir = `dirname $0`;
$cur_dir =~ s/\n//;
$opt = $ARGV[0];
my $file_ini = "/tmp/trackerssimple.ini";
my $file_txt = "$cur_dir/retrackers.txt";
open (CONFIG, "$cur_dir/patcher.conf") || die "Cannot open file $cur_dirpatcher.conf: $!";
while (<CONFIG>) {
my $comment = '#';
if(!($_ =~/^$comment/)) {
my ($param,$arg) = split("=",$_);
chomp $param;
chomp $arg;
$param =~ s/\s//g;
$arg =~ s/\s//g;
if ($param eq "fdirectory") {
$fdirectory = $arg;
}
if ($param eq "tdirectory") {
$tdirectory = $arg;
}
if ($param eq "sdirectory") {
$sdirectory = $arg;
}
if ($param eq "gorod") {
$gorod = $arg;
}
if ($param eq "prov") {
$prov = $arg;
}
}
}
close (CONFIG);
$isp="$gorod+$prov";
if ($opt eq "update") {
use LWP::Simple;
use IO::Socket;
use Config::IniFiles;
use Text::Iconv;
$u2k=new Text::Iconv("utf-16","koi8-r//translit");
$list=$u2k->convert(get "http://re-tracker.ru/trackerssimple.ini");
open (INI, ">$file_ini");
print INI "[description]\n$list";
close (INI);
$subject = Config::IniFiles->new( -file => $file_ini ) or die "Can`t parse file $file_ini: $!";
$gorod = $subject->val("Город", "$gorod");
$prov = $subject->val("Провайдеры $gorod", "$prov");
@values = $subject->Parameters("Ретрекеры $gorod $prov");
foreach (@values) {
$retracker = $subject->val("Ретрекеры $gorod $prov", $_);
if ($retracker=~ m!(http://[^/]+/[^\s]+)!ig) {
push(@list, $&);
}
}
@list = sort(@list);
binmode STDOUT,":bytes";
my $p = "";
my $out = "";
for $t(@list) {
next if $t eq $p;
$p=$t;
$t=~m#//(.+?)
\d+)/#;
$s=new IO::Socket::INET(PeerAddr=>$1,PeerPort=>$2,Timeout=>2);
if($s) {
$out .= "$t\n";
close $s;
}
open (RTR, ">$file_txt");
print RTR "$out";
close (RTR);
}
exit 0;
}
require "$cur_dir/tf.pl";
open(RTR, $file_txt) || die "Cannot open file $file_txt: $!";
my @retrackers=<RTR>;
close RTR;
sub patch {
$torrent = new TF ("$torrentfile");
$a = $torrent->announce();
@list = ([($a)]);
foreach $retracker (@retrackers) {
chomp $retracker;
$b="$retracker";
if ($retracker eq "http:\/\/re-tracker.ru:
\/announce.php") {
$size = $torrent->length();
if ($size == 0) {
$filesref = $torrent->files();
@files = @{$filesref};
foreach (@files) {
%file = %{$_};
$size = $size + $file{'length'};
}
}
$comment = $torrent->publisherurl();
if (!defined $comment) {
$comment = $torrent->comment();
}
# $comment =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
$b="$retracker?name=&size=$size&comment=$comment&isp=$isp";
}
@list=(@list, [($b)]);
}
$torrent->announcelist(@list);
}
if ($opt eq "current") {
opendir (TRR, "$sdirectory") || die "Cannot open $sdirectory: $!";
@tr = grep { !/^\.{1,2}$/ && (-f "$sdirectory"."/".$_) && /.torrent$/i } readdir TRR;
closedir TRR;
if (!defined @tr) {
exit 0;
} else {
foreach $tr(@tr) {
chomp $tr;
$torrentfile = "$sdirectory/$tr";
patch $torrentfile;
$torrent->save("$sdirectory/$tr");
}
}
} else {
opendir (TRR, "$fdirectory") || die "Cannot open $sdirectory: $!";
@tr = grep { !/^\.{1,2}$/ && (-f "$fdirectory"."/".$_) && /.torrent$/i } readdir TRR;
closedir TRR;
if (!defined @tr) {
exit 0;
} else {
foreach $tr(@tr) {
chomp $tr;
$torrentfile = "$fdirectory/$tr";
patch $torrentfile;
$torrent->save("$tdirectory/$tr");
system ("rm -f \"$fdirectory/$tr\"");
}
}
}
exit 0;