|
|
|
@ -77,7 +77,7 @@ def read_resume_data(info_hash): |
|
|
|
|
t_path = os.path.join(p, "%s.fastresume" % info_hash) |
|
|
|
|
if os.path.exists(t_path): |
|
|
|
|
with open(t_path, "rb") as fp: |
|
|
|
|
data = lt.read_resume_data(fp.read()) |
|
|
|
|
data = fp.read() |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
if data: |
|
|
|
@ -86,6 +86,12 @@ def read_resume_data(info_hash): |
|
|
|
|
raise ValueError("Fast Resume data not found") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lt_compatibility_convert(params): |
|
|
|
|
for k, v in params.items(): |
|
|
|
|
if type(v) == lt.sha1_hash: |
|
|
|
|
params[k] = v.to_bytes() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Session(lt.session): |
|
|
|
|
|
|
|
|
|
def __init__(self, conf, shutdown_cb): |
|
|
|
@ -283,6 +289,7 @@ class Session(lt.session): |
|
|
|
|
params_dict = torrent.get_params() |
|
|
|
|
|
|
|
|
|
params = None |
|
|
|
|
ti = None |
|
|
|
|
|
|
|
|
|
if "ti" in params_dict and params_dict["ti"]: |
|
|
|
|
try: |
|
|
|
@ -291,15 +298,28 @@ class Session(lt.session): |
|
|
|
|
log.exception("Opening torrent %s failed", info_hash) |
|
|
|
|
else: |
|
|
|
|
params_dict["ti"] = ti |
|
|
|
|
|
|
|
|
|
if ti: |
|
|
|
|
if lt_version < LooseVersion("1.2.0.0"): |
|
|
|
|
try: |
|
|
|
|
data = read_resume_data(info_hash) |
|
|
|
|
except Exception: |
|
|
|
|
log.exception("Reading resume data failed.") |
|
|
|
|
else: |
|
|
|
|
params_dict["resume_data"] = data |
|
|
|
|
else: |
|
|
|
|
try: |
|
|
|
|
params = read_resume_data(info_hash) |
|
|
|
|
data = read_resume_data(info_hash) |
|
|
|
|
params = lt.read_resume_data(data) |
|
|
|
|
except Exception: |
|
|
|
|
pass |
|
|
|
|
log.exception("Reading resume data failed.") |
|
|
|
|
else: |
|
|
|
|
params.trackers = list(set(params.trackers)) |
|
|
|
|
|
|
|
|
|
if lt_version < LooseVersion("1.1.1.0"): |
|
|
|
|
if lt_version < LooseVersion("1.2.0.0"): |
|
|
|
|
if params is None: |
|
|
|
|
log.warn("Falling back to < lt 1.2 compatibility handling.") |
|
|
|
|
lt_compatibility_convert(params_dict) |
|
|
|
|
params = params_dict |
|
|
|
|
else: |
|
|
|
|
if params is None: |
|
|
|
|