Search
Write a publication
Pull to refresh

Автоматическая закачка при обновлении торрент файла на torrents.ru

Навеено FlexGet или Бекапим инетернет автоматически). На torrents.ru обычно при постинге сериалов при выходи новой серии не создают новый топик а перезаливают торрент файл в уже имеющимся топике. Иногда в тексте пишут что топик обновился но когда? и закачивал ли я уже обновленный торрент? Вообщем что-бы не мучится и не пропустить новую серию любимого сериала и автоматизировать старт закачки накидал вот такой скриптец на Perl. Может кому нибудь он будет полезен. Работает он с µTorrent но думаю что легко можно адаптировать под любой торрент клиент. Для µTorrent скрипт просто кладет торрнет файл в опр. папку а µTorrent сам начинает закачку если в этой папке появился фал, после удаляет его.

#!/usr/bin/perl
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Cookies;
use File::Copy;
use strict;

my $ua;
while(1)
{

$ua=new LWP::UserAgent;
my $cookie=new HTTP::Cookies;
$ua->cookie_jar($cookie);

my $respons=$ua->post('http://login.torrents.ru/forum/login.php',
[login_username=>'username',
login_password=>'password',
login=>'']);

%{$ua->cookie_jar}->{COOKIES}{'torrents.ru'}=%{$ua->cookie_jar}->{COOKIES}{'.torrents.ru'};
$ua->cookie_jar->clear('.torrents.ru'); #так приходится делать из-за ошибки в либе, баг давно висит в трекере но на момент выхода скрипта не был исправлен

check('http://torrents.ru/forum/viewtopic.php?t=2243644'); #URL страници торрента

sleep 60*60; #Проверяем каждый час
}

sub check
{
  sleep 2; #Немного ждем что-бы не забанили
  my $respons=$ua->get(@_);
  sleep 2; #Немного ждем что-бы не забанили
  my @tor=$respons->content =~/(http:\/\/dl.torrents.ru\/forum\/dl.php\?t=(\d+))/igs;

  print @_;
  my $respons_tor=$ua->get($tor[0],':content_file'=>'new.torrent');

  if(open (FILE, '<'.$tor[1].'.torrent'))
  {
  my $file;
  my $new_file;
  while (<FILE>){$file.=$_}
  close (FILE);
  open (FILE, '<new.torrent');
  while (<FILE>){$new_file.=$_}
  close (FILE);
  
  if($file eq $new_file)
  {
    print "[old]\n";
    unlink('new.torrent');
    return;
  }
  }
  print "[new]\n";
  move('new.torrent',$tor[1].'.torrent');
  copy($tor[1].'.torrent', '../torrents_files/'.$tor[1].'.torrent');#Передаем файл торрент клиенту
}


* This source code was highlighted with Source Code Highlighter.
Tags:
Hubs:
You can’t comment this publication because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author’s username will be hidden by an alias.