15

.torrent ファイルからファイルセットを読み取るために、(すばやく) プログラム/スクリプトをまとめたいと考えています。次に、そのセットを使用して、トレントに属さない特定のディレクトリからファイルを削除します。

.torrent ファイルからこのインデックスを読み取るための便利なライブラリに関する推奨事項はありますか? 私はそれに異議を唱えませんが、ビットトレントの仕様を深く掘り下げて、この単純な目的のためにゼロから大量のコードをローリングしたくはありません。

言語にこだわりはありません。

4

5 に答える 5

25

小さくて高速な C++ ライブラリであるrasterbar のlibtorrentを使用します。
ファイルを反復処理するには、torrent_infoクラス (begin_files()、end_files()) を使用できます。

libtorrent 用のPython インターフェイスもあります。

import libtorrent
info = libtorrent.torrent_info('test.torrent')
for f in info.files():
    print "%s - %s" % (f.path, f.size)
于 2009-01-02T13:42:51.903 に答える
2

元の Mainline BitTorrent 5.x クライアント ( http://download.bittorrent.com/dl/BitTorrent-5.2.2.tar.gz )の bencode.py は、Python でのリファレンス実装のほとんどを提供します。

BTL パッケージへのインポート依存関係がありますが、これは簡単に削除できます。次に、bencode.bdecode(filecontent)['info']['files'] を調べます。

于 2009-01-02T13:00:33.660 に答える
1

上記のアイデアを拡張して、次のことを行いました。

~> cd ~/bin

~/bin> ls torrent*
torrent-parse.py  torrent-parse.sh

~/bin> cat torrent-parse.py
# torrent-parse.py
import sys
import libtorrent

# get the input torrent file
if (len(sys.argv) > 1):
    torrent = sys.argv[1]
else:
    print "Missing param: torrent filename"
    sys.exit()
# get names of files in the torrent file
info = libtorrent.torrent_info(torrent);
for f in info.files():
    print "%s - %s" % (f.path, f.size)

~/bin> cat torrent-parse.sh
#!/bin/bash
if [ $# -lt 1 ]; then
  echo "Missing param: torrent filename"
  exit 0
fi

python torrent-parse.py "$*"

シェル スクリプトを実行可能にするために、パーミッションを適切に設定する必要があります。

~/bin> chmod a+x torrent-parse.sh

これが誰かを助けることを願っています:)

于 2012-06-02T22:14:03.900 に答える