From 296d790421f455c9abac1e7a2ae5321d0bb6fa21 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Tue, 16 Mar 2010 01:14:27 +0000 Subject: [PATCH] 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 file changed, 16 insertions(+) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 8b4531247..aa30823f8 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()