use strict; use warnings; my $linecount = 0; open(DATA, qq(dumptorrent.exe "$ARGV[0]"|)); #binmode(DATA, ":encoding(UTF-8)"); binmode(STDOUT, ":encoding(UTF-8)"); foreach my $line () { # Discard the 5 lines of output before the list of filenames if (++$linecount > 5) { chomp $line; last if (length($line) == 0); $line =~ s/^ *//; $line =~ s/ +\([\d.]+[KMG]\)$//; # e.g. (8.22M) present for files larger than ~1k; discard it my $sizeindex = rindex($line, ' ') + 1; my $filesize = substr($line, $sizeindex); # Ignore zero-length files in torrents. if (defined $filesize && length($filesize) > 0 && $filesize > 0) { (my $filename = $line) =~ s/ +\d+$//; my $filekey = "$filename $filesize"; print "$filekey\n"; } } }