* parse .torrent file and print list of files
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Tue, 10 Apr 2012 15:47:14 +0000 (15:47 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Tue, 10 Apr 2012 15:47:14 +0000 (15:47 +0000)
 * this script couldn't many .torrent file because of Convert::Bencode bugs like below
{{{
Use of uninitialized value $item in string eq at Perl/site/lib/Convert/Bencode.pm line 127.
Use of uninitialized value $item in string eq at Perl/site/lib/Convert/Bencode.pm line 138.
Use of uninitialized value $item in string eq at Perl/site/lib/Convert/Bencode.pm line 148.
}}}

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@135 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

misc/torrent2filelist.pl [new file with mode: 0644]

diff --git a/misc/torrent2filelist.pl b/misc/torrent2filelist.pl
new file mode 100644 (file)
index 0000000..09eb51d
--- /dev/null
@@ -0,0 +1,27 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Net::BitTorrent::File;
+use Data::Dumper;
+
+my $torretfile = shift @ARGV;
+my $torrent = Net::BitTorrent::File->new($torretfile) or
+    die "$0: cannot load torrent file: $torretfile";
+
+my $files = $torrent->files;
+if ($files) {
+    foreach my $file (@$files) {
+        if (exists $file->{'path.utf-8'}) {
+            print $torrent->name, "/", join ("/", @{ $file->{'path.utf-8'} }), "\n";
+        }
+        else {
+            print $torrent->name, "/", join ("/", @{ $file->{'path'} }), "\n";
+            
+        }
+    }
+}
+else {
+    print $torrent->name, "\n";
+}