mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-26 10:05:19 +00:00
actually commit ui.common this time
This commit is contained in:
parent
ca316750e8
commit
5acd9f3f21
@ -92,6 +92,15 @@ class TorrentInfo(object):
|
|||||||
"download": True
|
"download": True
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def as_dict(self, *keys):
|
||||||
|
"""
|
||||||
|
Return the torrent info as a dictionary, only including the passed in
|
||||||
|
keys.
|
||||||
|
|
||||||
|
:param *keys: str, a number of key strings
|
||||||
|
"""
|
||||||
|
return dict([(key, getattr(self, key)) for key in keys])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__m_metadata["info"]["name"]
|
return self.__m_metadata["info"]["name"]
|
||||||
@ -184,52 +193,6 @@ class FileTree(object):
|
|||||||
self.walk(write)
|
self.walk(write)
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
def get_torrent_info(filename):
|
|
||||||
"""
|
|
||||||
Return the metadata of a torrent file
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Get the torrent data from the torrent file
|
|
||||||
try:
|
|
||||||
log.debug("Attempting to open %s.", filename)
|
|
||||||
metadata = bencode.bdecode(open(filename, "rb").read())
|
|
||||||
except Exception, e:
|
|
||||||
log.warning("Unable to open %s: %s", filename, e)
|
|
||||||
raise e
|
|
||||||
|
|
||||||
info_hash = sha(bencode.bencode(metadata["info"])).hexdigest()
|
|
||||||
|
|
||||||
# Get list of files from torrent info
|
|
||||||
paths = {}
|
|
||||||
if metadata["info"].has_key("files"):
|
|
||||||
prefix = ""
|
|
||||||
if len(metadata["info"]["files"]) > 1:
|
|
||||||
prefix = metadata["info"]["name"]
|
|
||||||
|
|
||||||
for f in metadata["info"]["files"]:
|
|
||||||
path = os.path.join(prefix, *f["path"])
|
|
||||||
paths[path] = f
|
|
||||||
|
|
||||||
def walk(path, item):
|
|
||||||
if type(item) is dict:
|
|
||||||
return item
|
|
||||||
return [paths[path]['length'], True]
|
|
||||||
|
|
||||||
file_tree = FileTree(paths)
|
|
||||||
file_tree.walk(walk)
|
|
||||||
files = file_tree.get_tree()
|
|
||||||
else:
|
|
||||||
files = {
|
|
||||||
metadata["info"]["name"]: (metadata["info"]["length"], True)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"filename": filename,
|
|
||||||
"name": metadata["info"]["name"],
|
|
||||||
"files": files,
|
|
||||||
"info_hash": info_hash
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_localhost_auth():
|
def get_localhost_auth():
|
||||||
"""
|
"""
|
||||||
Grabs the localclient auth line from the 'auth' file and creates a localhost uri
|
Grabs the localclient auth line from the 'auth' file and creates a localhost uri
|
||||||
|
Loading…
x
Reference in New Issue
Block a user