Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wrote a quickie perl script for updating torrent links
#1
Hi there - I wrote a short perl script for taking the current torrent links and changing what trackers are being used, thought I'd share!

It expects to have a txt file containing the current magnet links in the same directory as the script. It'll read that in, and spit out the links formatted for posting to MyBB. This way, whenever it's time to update the URLs, you just change the trackers at the beginning of the script and run it.

I tried to just use modules that come pre-installed with most perl distributions, so hopefully it should just work everywhere without a lot of fuss.

Code:
#!/usr/bin/env perl

use strict;
use warnings;
use URI;
use URI::Escape;

my @trackers = qw[
udp://tracker.opentrackr.org:1337
udp://tracker.coppersurfer.tk:6969
udp://tracker.leechers-paradise.org:6969
udp://zer0day.ch:1337
udp://explodie.org:6969
];

open(my $fh, '<', '16bap.txt');
while(<$fh>) {
   my $line = $_;
   my $url = URI->new($line);
   my @params = $url->query_form();
   my $title = '';
   my $newurl = 'magnet:?';
   my $something_added = 0;
   for(my $i=0; $i<$#params; $i+=2) {
       if($params[$i] ne 'tr') {
           if($something_added) {
               $newurl .= '&';
           }
           else {
               $something_added = 1;
           }
           if($params[$i] eq 'xt') {
               $newurl .= $params[$i].'='.$params[$i+1];
           }
           else {
               $newurl .= $params[$i].'='.uri_escape($params[$i+1])
           }
       }
       if($params[$i] eq 'dn') {
           $title = uri_unescape($params[$i+1]);
           $title =~ s/\+/ /g;
       }
   }
   foreach my $tracker (@trackers) {
       if($something_added) {
           $newurl .= '&';
       }
       else {
           $something_added = 1;
       }
       $newurl .= 'tr='.uri_escape($tracker);
   }
   print(sprintf('%s - [url=%s]Download via torrent[/url]',$title,$newurl)."\n");
}
close($fh);
Reply
#2
Thank you so much for this! It will definitely come in handy!
Vi veri veniversum vivus vici
Reply


Forum Jump: