diff --git a/sickbeard/providers/hounddawgs.py b/sickbeard/providers/hounddawgs.py index 8bb7c8a1454545e19c1f280317864277c2d00a8d..c5f1fb6202a7b083b2e74c3ac2fc792a455ca6f5 100644 --- a/sickbeard/providers/hounddawgs.py +++ b/sickbeard/providers/hounddawgs.py @@ -21,10 +21,11 @@ import traceback from sickbeard import logger from sickbeard import tvcache from sickbeard.bs4_parser import BS4Parser +from sickrage.helper.common import try_int from sickrage.providers.TorrentProvider import TorrentProvider -class HoundDawgsProvider(TorrentProvider): +class HoundDawgsProvider(TorrentProvider): # pylint: disable=too-many-instance-attributes def __init__(self): @@ -35,12 +36,15 @@ class HoundDawgsProvider(TorrentProvider): self.ratio = None self.minseed = None self.minleech = None + self.freeleech = None + self.ranked = None - self.cache = HoundDawgsCache(self) - self.urls = {'base_url': 'https://hounddawgs.org/', - 'search': 'https://hounddawgs.org/torrents.php', - 'login': 'https://hounddawgs.org/login.php'} + self.urls = { + 'base_url': 'https://hounddawgs.org/', + 'search': 'https://hounddawgs.org/torrents.php', + 'login': 'https://hounddawgs.org/login.php' + } self.url = self.urls['base_url'] @@ -60,12 +64,16 @@ class HoundDawgsProvider(TorrentProvider): "searchtags": '' } + self.cache = HoundDawgsCache(self) + def login(self): - login_params = {'username': self.username, - 'password': self.password, - 'keeplogged': 'on', - 'login': 'Login'} + login_params = { + 'username': self.username, + 'password': self.password, + 'keeplogged': 'on', + 'login': 'Login' + } self.get_url(self.urls['base_url'], timeout=30) response = self.get_url(self.urls['login'], post_data=login_params, timeout=30) @@ -81,7 +89,7 @@ class HoundDawgsProvider(TorrentProvider): return True - def search(self, search_strings, age=0, ep_obj=None): + def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-many-locals,too-many-branches,too-many-statements results = [] items = {'Season': [], 'Episode': [], 'RSS': []} @@ -127,25 +135,20 @@ class HoundDawgsProvider(TorrentProvider): allAs = (torrent[1]).find_all('a') try: - # link = self.urls['base_url'] + allAs[2].attrs['href'] - # url = result.find('td', attrs={'class': 'quickdownload'}).find('a') + notinternal = result.find('img', src='/static//common/user_upload.png') + if self.ranked and notinternal: + logger.log(u"Found a user uploaded release, Ignoring it..", logger.DEBUG) + continue + freeleech = result.find('img', src='/static//common/browse/freeleech.png') + if self.freeleech and not freeleech: + continue title = allAs[2].string - # Trimming title so accepted by scene check(Feature has been rewuestet i forum) - title = title.replace("custom.", "") - title = title.replace("CUSTOM.", "") - title = title.replace("Custom.", "") - title = title.replace("dk", "") - title = title.replace("DK", "") - title = title.replace("Dk", "") - title = title.replace("subs.", "") - title = title.replace("SUBS.", "") - title = title.replace("Subs.", "") - download_url = self.urls['base_url']+allAs[0].attrs['href'] - # FIXME - size = -1 - seeders = 1 - leechers = 0 + torrent_size = result.find("td", class_="nobr").find_next_sibling("td").string + if torrent_size: + size = self._convertSize(torrent_size) + seeders = try_int((result.findAll('td')[6]).text) + leechers = try_int((result.findAll('td')[7]).text) except (AttributeError, TypeError): continue @@ -154,10 +157,10 @@ class HoundDawgsProvider(TorrentProvider): continue # Filter unseeded torrent - # if seeders < self.minseed or leechers < self.minleech: - # if mode != 'RSS': - # logger.log(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers), logger.DEBUG) - # continue + if seeders < self.minseed or leechers < self.minleech: + if mode != 'RSS': + logger.log(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers), logger.DEBUG) + continue item = title, download_url, size, seeders, leechers if mode != 'RSS': @@ -165,7 +168,7 @@ class HoundDawgsProvider(TorrentProvider): items[mode].append(item) - except Exception, e: + except Exception: logger.log(u"Failed parsing provider. Traceback: %s" % traceback.format_exc(), logger.ERROR) # For each search mode sort all the items by seeders if available @@ -175,6 +178,21 @@ class HoundDawgsProvider(TorrentProvider): return results + + @staticmethod + def _convertSize(size): + size = re.sub(r'[i, ]+', '', size) + matches = re.match(r'([\d.]+)([TGMK])', size.strip().upper()) + if not matches: + return -1 + + size = matches.group(1) + modifier = matches.group(2) + + mod = {'K': 1, 'M': 2, 'G': 3, 'T': 4} + return float(size) * 1024**mod[modifier] + + def seed_ratio(self): return self.ratio