最後還是使用 Java 來處理,雖然沒 Python 來得簡單.
但是配合上自寫的 bat script 就差不多了,只要將檔案放到 seed 目錄,執行 bat 就可以
雖然還沒完整處理輸出編碼問題,但還是算得上可用吧.
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
|
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Map;
import bencode.*;
class Torrent { public static void main(String[] args) { if (args.length == 0) { println("Usage: java Torrent [torrent file]"); }else if (new File(args[0]).exists()) { try { BDecoder be = new BDecoder(new FileInputStream(args[0])); Map m = be.bdecodeMap().getMap(); BEValue val = (BEValue)m.get("info"); Map info = val.getMap();
val = (BEValue)info.get("name"); String name = val.getString();
print(name);
}catch(IOException e) {} }else{ print("File Not Found: " + args[0]); } }
private static void print(String str) { System.out.print(str); }
private static void println(String str) { System.out.println(str); } }
|
附上檔案: Torrent.7z