make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / mkmagnetlink
blob721ba7bf9f46461873339c27b2691ebdc8e82f58
1 #!/usr/bin/env perl
3 for my $file (@ARGV)
5 my $hash = '';
6 my $trackers = '';
7 my $trackers_section = 0;
9 open my $pipe, '-|', "transmission-show", $file or warn "transmission-show $file: $!\n";
10 while(<$pipe>)
12 /^\s*Hash:\s*(\S+)/ and $hash = $1;
13 /^TRACKERS/ and $trackers_section = 1;
14 /^(?!TRACKERS)\S/ and $trackers_section = 0;
15 if($trackers_section and /^\s*Tier/)
17 my $tracker = <$pipe>;
18 $tracker =~ s/^\s*//;
19 $tracker =~ s/\s*$//;
20 $tracker =~ s/[^a-zA-Z0-9._-]/sprintf "%%%02X", ord $&/ige;
21 $trackers .= '&tr='.$tracker;
24 close $pipe;
26 print "magnet:?xt=urn:btih:$hash$trackers\n";
29 __END__
31 =pod
33 =head1 NAME
35 mkmagnetlink - Create a "magnet:" link out of a torrent file
37 =cut