Bittorrent

Aus Mikiwiki
Version vom 16. Januar 2009, 11:10 Uhr von Michi (Diskussion | Beiträge) (New page: ==Verwendung== I wanted to run torrents from my Linux server, rather than running them on my Windows laptop. Further, I wanted a system that needed very little intervention. To start th...)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Verwendung

I wanted to run torrents from my Linux server, rather than running them on my Windows laptop. Further, I wanted a system that needed very little intervention.

To start the torrent daemon, I run the following:

 (/usr/bin/btlaunchmany.py /home/share/video/torrents/active/ --save_in /home/share/video/torrents/ --minport 6885 --max_upload_rate 10 \
 > /home/share/video/torrents/torrent.log 2>&1 &) &

To parse the torrent log, I use a small perl script, which runs as a daemon:

#!/usr/bin/perl

use Data::Dumper;
use Term::Screen;
use strict;

my $scr = Term::Screen->new();

my $first;
my $entry = {};
while (my $line = <STDIN>)
{
  next unless ($line =~ m#^"(.*?)":\s+"(.*?)"\s+(\S+)\s(\S+)\s(.*?)"(.*?)"\n#);
  my %info;
  $info{file} = $1;
  $info{status} = $2;
  $info{percent} = $3;
  # unknown = $4;
  my $transfer_line = $5;
  # unknown = $6;

if ($6) { print "** $6\n"; }

  my @transfer = split(/\s+/, $transfer_line);
  $info{rate} = $transfer[1];
  $info{total} = $transfer[2];

  if ($info{file} eq $first)
  {
    showEntries($entry, $scr);
  }
  $first ||= $info{file};

  my $file = $info{file};
  $entry->{$file} = \%info;
  #print $info{file}, "\n", join("\t", $info{status}, $info{percent}), "\n",
  #  join("\t", $info{rate}, $info{total}), "\n\n";
}

sub showEntries
{
  my ($h, $s) = @_;

  $s->clrscr();

  open(OUT, "> /tmp/torrent-status") || die "can't open torrent-status: $!";
  while (my ($file, $e) = each %$h)
  {
    print OUT $e->{file}, "\n", join("\t", $e->{status}, $e->{percent}, $e->{rate}, $e->{total}), "\n\n";
  }
  close OUT;
}

To start or stop torrents, I simply place the torrent file in a directory, or remove the torrent from the directory. The torrent daemon picks them up automagically. The directory (in the above example) is "/home/share/video/torrents/active/".

Downloads

Weblinks