From cd16dddf13075e377d3c6c1f43250017c893cbc9 Mon Sep 17 00:00:00 2001
From: Ruud <ruud@crashdummy.nl>
Date: Fri, 8 Mar 2013 14:45:32 +0100
Subject: [PATCH] Make sure to use the correct hash for utorrent

---
 couchpotato/core/downloaders/utorrent/main.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py
index 389a0a6f..6f290242 100644
--- a/couchpotato/core/downloaders/utorrent/main.py
+++ b/couchpotato/core/downloaders/utorrent/main.py
@@ -1,3 +1,4 @@
+from base64 import b16encode, b32decode
 from bencode import bencode, bdecode
 from couchpotato.core.downloaders.base import Downloader
 from couchpotato.core.helpers.encoding import isInt, ss
@@ -42,8 +43,13 @@ class uTorrent(Downloader):
             torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper()
             torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers)
         else:
-            info = bdecode(filedata)["info"]
-            torrent_hash = sha1(bencode(info)).hexdigest().upper()
+            # Convert base 32 to hex
+            if len(torrent_hash) == 32:
+                torrent_hash = b16encode(b32decode(torrent_hash))
+            else:
+                info = bdecode(filedata)["info"]
+                torrent_hash = sha1(bencode(info)).hexdigest().upper()
+
             torrent_filename = self.createFileName(data, filedata, movie)
 
         # Send request to uTorrent
-- 
GitLab