[#2347] Add orig_files to core

This commit is contained in:
Calum Lind 2014-07-17 21:43:29 +01:00
parent 739d8f329a
commit 25c7e40574

View File

@ -56,6 +56,34 @@ def sanitize_filepath(filepath, folder=False):
else: else:
return newfilepath return newfilepath
def convert_lt_files(self, files):
"""Indexes and decodes files from libtorrent get_files().
Args:
files (list): The libtorrent torrent files.
Returns:
list of dict: The files.
The format for the file dict::
{
"index": int,
"path": str,
"size": int,
"offset": int
}
"""
filelist = []
for index, _file in enumerate(files):
filelist.append({
"index": index,
"path": _file.path.decode("utf8").replace("\\", "/"),
"size": _file.size,
"offset": _file.offset
})
return filelist
class TorrentOptions(dict): class TorrentOptions(dict):
"""TorrentOptions create a dict of the torrent options. """TorrentOptions create a dict of the torrent options.
@ -646,6 +674,7 @@ class Torrent(object):
Returns: Returns:
float: The ratio or -1.0 (for infinity). float: The ratio or -1.0 (for infinity).
""" """
if self.status.total_done > 0: if self.status.total_done > 0:
return self.status.all_time_upload / self.status.total_done return self.status.all_time_upload / self.status.total_done
@ -658,27 +687,25 @@ class Torrent(object):
Returns: Returns:
list of dict: The files. list of dict: The files.
The format for the file dict::
{
"index": int,
"path": str,
"size": int,
"offset": int
}
""" """
if not self.has_metadata: if not self.has_metadata:
return [] return []
ret = []
files = self.torrent_info.files() files = self.torrent_info.files()
for index, _file in enumerate(files): return convert_lt_files(files)
ret.append({
"index": index, def get_orig_files(self):
"path": _file.path.decode("utf8").replace("\\", "/"), """Get the original filenames of files in this torrent.
"size": _file.size,
"offset": _file.offset Returns:
}) list of dict: The files with original filenames.
return ret
"""
if not self.has_metadata:
return []
files = self.torrent_info.orig_files()
return convert_lt_files(files)
def get_peers(self): def get_peers(self):
"""Get the peers for this torrent. """Get the peers for this torrent.
@ -944,6 +971,7 @@ class Torrent(object):
"eta": self.get_eta, "eta": self.get_eta,
"file_progress": self.get_file_progress, # Adjust progress to be 0-100 value "file_progress": self.get_file_progress, # Adjust progress to be 0-100 value
"files": self.get_files, "files": self.get_files,
"orig_files": self.get_orig_files,
"is_seed": lambda: self.status.is_seeding, "is_seed": lambda: self.status.is_seeding,
"peers": self.get_peers, "peers": self.get_peers,
"queue": lambda: self.status.queue_position, "queue": lambda: self.status.queue_position,