From 0042f60bbbc4df59ec225475251306b7935991c8 Mon Sep 17 00:00:00 2001
From: labrys <labrys@users.noreply.github.com>
Date: Thu, 7 Jan 2016 06:36:32 -0500
Subject: [PATCH] Fix file size conversion for torrentleech

---
 sickbeard/providers/torrentleech.py | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/sickbeard/providers/torrentleech.py b/sickbeard/providers/torrentleech.py
index b4596a75d..b2210ba88 100644
--- a/sickbeard/providers/torrentleech.py
+++ b/sickbeard/providers/torrentleech.py
@@ -23,10 +23,9 @@ import urllib
 from sickbeard import logger
 from sickbeard import tvcache
 from sickbeard.bs4_parser import BS4Parser
+from sickrage.helper.common import try_int, convert_size
 from sickrage.providers.torrent.TorrentProvider import TorrentProvider
 
-from sickrage.helper.common import try_int
-
 
 class TorrentLeechProvider(TorrentProvider):
 
@@ -116,7 +115,9 @@ class TorrentLeechProvider(TorrentProvider):
 
                             seeders = try_int(result.find('td', class_='seeders').get_text(strip=True))
                             leechers = try_int(result.find('td', class_='leechers').get_text(strip=True))
-                            size = self._convertSize(result.find_all('td')[labels.index('Size')].get_text(strip=True))
+                            torrent_size = result.find_all('td')[labels.index('Size')].get_text()
+
+                            size = convert_size(torrent_size) or -1
                         except (AttributeError, TypeError, KeyError, ValueError):
                             continue
 
@@ -145,26 +146,6 @@ class TorrentLeechProvider(TorrentProvider):
     def seed_ratio(self):
         return self.ratio
 
-    @staticmethod
-    def _convertSize(size):
-        modifier = size[-2:].upper()
-        size = size[:-2].strip()
-        try:
-            size = float(size)
-            if modifier in 'KB':
-                size = size * 1024 ** 1
-            elif modifier in 'MB':
-                size = size * 1024 ** 2
-            elif modifier in 'GB':
-                size = size * 1024 ** 3
-            elif modifier in 'TB':
-                size = size * 1024**4
-            else:
-                raise
-        except Exception:
-            size = -1
-
-        return long(size)
 
 class TorrentLeechCache(tvcache.TVCache):
     def __init__(self, provider_obj):
-- 
GitLab