Module: deluge
Branch: master
Commit: 296d790421f455c9abac1e7a2ae5321d0bb6fa21

Author: Damien Churchill <[email protected]>
Date:   Tue Mar 16 01:14:27 2010 +0000

If the torrent has been added via a magnet link then try and extract the name 
from the dn key in the url. Fixes #1154.

---

 deluge/core/torrent.py |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py
index 8b45312..aa30823 100644
--- a/deluge/core/torrent.py
+++ b/deluge/core/torrent.py
@@ -36,6 +36,7 @@
 
 import os
 import time
+from urllib import unquote
 from urlparse import urlparse
 
 from deluge._libtorrent import lt
@@ -626,7 +627,22 @@ class Torrent(object):
                 except UnicodeDecodeError:
                     return name
 
+            elif self.magnet:
+                try:
+                    keys = dict([k.split('=') for k in 
self.magnet.split('?')[-1].split('&')])
+                    name = keys.get('dn')
+                    if not name:
+                        return self.torrent_id
+                    name = unquote(name).replace('+', ' ')
+                    try:
+                        return name.decode("utf8", "ignore")
+                    except UnicodeDecodeError:
+                        return name
+                except:
+                    pass
+
             return self.torrent_id
+
         def ti_priv():
             if self.handle.has_metadata():
                 return self.torrent_info.priv()

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to