Add the files_tree property to TorrentInfo
This commit is contained in:
parent
cab504c90e
commit
5e4ee41db2
|
@ -48,29 +48,30 @@ class TorrentInfo(object):
|
|||
|
||||
self.__m_info_hash = sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
|
||||
|
||||
"""# Get list of files from torrent info
|
||||
# Get list of files from torrent info
|
||||
paths = {}
|
||||
if metadata["info"].has_key("files"):
|
||||
if self.__m_metadata["info"].has_key("files"):
|
||||
prefix = ""
|
||||
if len(metadata["info"]["files"]) > 1:
|
||||
prefix = metadata["info"]["name"]
|
||||
if len(self.__m_metadata["info"]["files"]) > 1:
|
||||
prefix = self.__m_metadata["info"]["name"]
|
||||
|
||||
for f in metadata["info"]["files"]:
|
||||
for index, f in enumerate(self.__m_metadata["info"]["files"]):
|
||||
path = os.path.join(prefix, *f["path"])
|
||||
f["index"] = index
|
||||
paths[path] = f
|
||||
|
||||
def walk(path, item):
|
||||
if type(item) is dict:
|
||||
return item
|
||||
return [paths[path]['length'], True]
|
||||
return [paths[path]['index'], paths[path]['length'], True]
|
||||
|
||||
file_tree = FileTree(paths)
|
||||
file_tree.walk(walk)
|
||||
self.__m_files = file_tree.get_tree()
|
||||
self.__m_files_tree = file_tree.get_tree()
|
||||
else:
|
||||
self.__m_files = {
|
||||
metadata["info"]["name"]: (metadata["info"]["length"], True)
|
||||
}"""
|
||||
self.__m_files_tree = {
|
||||
self.__m_metadata["info"]["name"]: (self.__m_metadata["info"]["length"], True)
|
||||
}
|
||||
|
||||
self.__m_files = []
|
||||
if self.__m_metadata["info"].has_key("files"):
|
||||
|
@ -103,6 +104,10 @@ class TorrentInfo(object):
|
|||
def files(self):
|
||||
return self.__m_files
|
||||
|
||||
@property
|
||||
def files_tree(self):
|
||||
return self.__m_files_tree
|
||||
|
||||
@property
|
||||
def metadata(self):
|
||||
return self.__m_metadata
|
||||
|
|
Loading…
Reference in New Issue