summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2016-09-19 15:00:08 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2016-09-19 15:00:08 +0300
commitc8344819e060965bddac5628f0e716e1fe2f0b1f (patch)
tree5331ecc2769ff7637c722c0cd2dfb682b291a94c
parent09440577a04cabedeca1792f72d3ed0364dae720 (diff)
libtorrent compatibility fixes
-rw-r--r--epour/session.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/epour/session.py b/epour/session.py
index 32c92a1..29fee9e 100644
--- a/epour/session.py
+++ b/epour/session.py
@@ -77,7 +77,7 @@ def read_resume_data(info_hash):
77 t_path = os.path.join(p, "%s.fastresume" % info_hash) 77 t_path = os.path.join(p, "%s.fastresume" % info_hash)
78 if os.path.exists(t_path): 78 if os.path.exists(t_path):
79 with open(t_path, "rb") as fp: 79 with open(t_path, "rb") as fp:
80 data = lt.read_resume_data(fp.read()) 80 data = fp.read()
81 break 81 break
82 82
83 if data: 83 if data:
@@ -86,6 +86,12 @@ def read_resume_data(info_hash):
86 raise ValueError("Fast Resume data not found") 86 raise ValueError("Fast Resume data not found")
87 87
88 88
89def lt_compatibility_convert(params):
90 for k, v in params.items():
91 if type(v) == lt.sha1_hash:
92 params[k] = v.to_bytes()
93
94
89class Session(lt.session): 95class Session(lt.session):
90 96
91 def __init__(self, conf, shutdown_cb): 97 def __init__(self, conf, shutdown_cb):
@@ -283,6 +289,7 @@ class Session(lt.session):
283 params_dict = torrent.get_params() 289 params_dict = torrent.get_params()
284 290
285 params = None 291 params = None
292 ti = None
286 293
287 if "ti" in params_dict and params_dict["ti"]: 294 if "ti" in params_dict and params_dict["ti"]:
288 try: 295 try:
@@ -291,15 +298,28 @@ class Session(lt.session):
291 log.exception("Opening torrent %s failed", info_hash) 298 log.exception("Opening torrent %s failed", info_hash)
292 else: 299 else:
293 params_dict["ti"] = ti 300 params_dict["ti"] = ti
301
302 if ti:
303 if lt_version < LooseVersion("1.2.0.0"):
304 try:
305 data = read_resume_data(info_hash)
306 except Exception:
307 log.exception("Reading resume data failed.")
308 else:
309 params_dict["resume_data"] = data
310 else:
294 try: 311 try:
295 params = read_resume_data(info_hash) 312 data = read_resume_data(info_hash)
313 params = lt.read_resume_data(data)
296 except Exception: 314 except Exception:
297 pass 315 log.exception("Reading resume data failed.")
298 else: 316 else:
299 params.trackers = list(set(params.trackers)) 317 params.trackers = list(set(params.trackers))
300 318
301 if lt_version < LooseVersion("1.1.1.0"): 319 if lt_version < LooseVersion("1.2.0.0"):
302 if params is None: 320 if params is None:
321 log.warn("Falling back to < lt 1.2 compatibility handling.")
322 lt_compatibility_convert(params_dict)
303 params = params_dict 323 params = params_dict
304 else: 324 else:
305 if params is None: 325 if params is None: