get files from torrent file

This commit is contained in:
j 2009-09-03 18:29:04 +02:00
parent 827674c85d
commit 56e4f0b539

View file

@ -5,6 +5,7 @@
from threading import Event from threading import Event
import hashlib import hashlib
from os import stat from os import stat
import os
from BitTornado.BT1.makemetafile import make_meta_file from BitTornado.BT1.makemetafile import make_meta_file
from bencode import bencode, bdecode from bencode import bencode, bdecode
@ -55,6 +56,18 @@ def getTorrentInfo(data):
tinfo['announce'] = metainfo['announce'] tinfo['announce'] = metainfo['announce']
return tinfo return tinfo
def getFiles(data):
files = []
info = getTorrentInfo(data)
if 'files' in info:
for f in info['files']:
path = [info['name'], ]
path.extend(f['path'])
files.append(os.path.join(*path))
else:
files.append(info['name'])
return files
def getTorrentSize(torrentFile): def getTorrentSize(torrentFile):
"Returns Size of files in torrent file in bytes" "Returns Size of files in torrent file in bytes"
return getTorrentInfo(torrentFile)['size'] return getTorrentInfo(torrentFile)['size']