kuuko pushed a commit to branch master.

http://git.enlightenment.org/apps/epour.git/commit/?id=5541a2ad759a4ef5bae9e7b7797f6e3c356d2dde

commit 5541a2ad759a4ef5bae9e7b7797f6e3c356d2dde
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Fri Jul 18 22:13:36 2014 +0300

    Fix save and restore of torrents without metadata
---
 epour/session.py | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/epour/session.py b/epour/session.py
index f3234d2..d869736 100644
--- a/epour/session.py
+++ b/epour/session.py
@@ -180,12 +180,14 @@ class Session(lt.session):
                     try:
                         if isinstance(t, dict):
                             for k, v in t.items():
-                                if k == "ti":
+                                if v is None:
+                                    continue
+                                elif k == "ti":
                                     t[k] = lt.torrent_info(lt.bdecode(v))
                                     # with open(v, "rb") as f:
                                     #     torrents[i][k] = \
                                     #         
lt.torrent_info(lt.bdecode(f.read()))
-                                if k == "info_hash":
+                                elif k == "info_hash":
                                     torrents[i][k] = lt.big_number(v)
                         else:
                             # Upgrade from older versions where t is file path
@@ -219,17 +221,22 @@ class Session(lt.session):
                     else:
                         self.torrents[i][k] = v.to_string()
 
-        for h in self.get_torrents():
-            if h.is_valid() and h.has_metadata():
+        handles = self.get_torrents()
+        for h in handles:
+            if h.is_valid():
                 i = str(h.info_hash())
                 t_dict = self.torrents[i]
-                t_info = h.get_torrent_info()
-                t = {}
-                t["info"] = lt.bdecode(t_info.metadata())
-                t_dict["ti"] = lt.bencode(t)
                 t_dict["save_path"] = h.save_path()
-                resume_data = lt.bencode(h.write_resume_data())
-                t_dict["resume_data"] = resume_data
+                s = h.status(0)
+                if s.has_metadata:
+                    resume_data = lt.bencode(h.write_resume_data())
+                    t_dict["resume_data"] = resume_data
+                    t_info = h.get_torrent_info()
+                    t = {}
+                    t["info"] = lt.bdecode(t_info.metadata())
+                    t_dict["ti"] = lt.bencode(t)
+            else:
+                self.log.debug("Handle is invalid, skipping")
 
         path = os.path.join(save_data_path("epour"), "torrents")
         with open(path, 'wb') as f:

-- 


Reply via email to