Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 078c55e81a
Fetching contributors…

Cannot retrieve contributors at this time

executable file 49 lines (39 sloc) 1.335 kb
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
#!/usr/bin/perl -T
use strict;
use warnings;

use Mojo::UserAgent;

#use Transmission::Utils;
use Transmission::Client;

my $torrent_uri = 'http://openbsd.somedomain.net/torrent/';
my $download_dir = ''; # If you want to override

use lib 'lib';
eval { require OpenBSDTorrents };
unless ($@) {
    $torrent_uri = $OpenBSDTorrents::OBT->{URL_TORRENTS};
    $download_dir = $OpenBSDTorrents::OBT->{DIR_FTP};
}

my $current
    = Mojo::UserAgent->new->get( $torrent_uri . 'torrents.json' )->res->json;
die "Couldn't get current torrents" unless $current;

my $client = Transmission::Client->new;
foreach my $torrent ( @{ $client->torrents } ) {
    next unless $torrent->comment =~ /OpenBSD.somedomain.net/;
    my $hash = $torrent->hash_string;

    if ( exists $current->{$hash} ) {
        delete $current->{$hash}; # No need to do anything
    }
    else {
        print "No longer seeding [$hash]\n";
        $torrent->stop or warn $torrent->error_string;
        $client->remove( $torrent->id ) or warn $client->error;
    }
}

foreach my $hash ( keys %{$current} ) {
    my $file = $current->{$hash}{torrent};
    print "Starting seed of [$file] [$hash]\n";

    $client->add(
        filename => $torrent_uri . $file,
        download_dir => $download_dir,
    ) || warn $client->error, ": $file\n";
}

$client->start;
Something went wrong with that request. Please try again.