From 851f58122f89c436b5dc355a5fabd7cfed2830d0 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Thu, 24 May 2018 16:51:22 +0100 Subject: [PATCH] Add HorribleSubs torrent provider. --- CHANGES.md | 1 + gui/slick/images/providers/horriblesubs.png | Bin 0 -> 535 bytes sickbeard/providers/__init__.py | 3 +- sickbeard/providers/horriblesubs.py | 96 ++++++++++++++++++++ sickbeard/search.py | 4 +- 5 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 gui/slick/images/providers/horriblesubs.png create mode 100644 sickbeard/providers/horriblesubs.py diff --git a/CHANGES.md b/CHANGES.md index 0c6641fb..9ab994d9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ * Update Tornado Web Server 5.0.1 (35a538f) to 5.0.1 (2b2a220a) * Add HDME torrent provider +* Add HorribleSubs torrent provider * Add ImmortalSeed torrent provider * Add Xspeeds torrent provider * Change consolidate provider filters into 'Only allow releases that are' diff --git a/gui/slick/images/providers/horriblesubs.png b/gui/slick/images/providers/horriblesubs.png new file mode 100644 index 0000000000000000000000000000000000000000..92377a9d2a0143e5a9390d67cdde07e3e7009b44 GIT binary patch literal 535 zcmV+y0_gpTP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5C8xR5CN?ty>$Qp0jx|ya1lP#OOAj)KeK`B_E@Yx>Pie`S~&~v`_Tw4zs9sSXD zof8YPTX&#e2cQ5$r!wZsp>>>f&NeaP`HpnW+4C+yj}9+q6EHvNEyXvYhJU@l{Co<3 zwCH)M5}2~RVV3g15l!E)9nDaDGKjRq;^Gl`kb3Yj zmRHYMTs}f%U$l343c*80Iwd8)79QW{D31kgB=d->(5Sf}vF(MEEe^8?QZ#7F+VS3Y zyu|0j8)g2OY|!wEHte8mb-InXPW7 z{X0;S?=lq8&y8Q`LX+E5KjSA#?v)3~N>m Z;2Sy$=Br_KCvE@$002ovPDHLkV1ii;>ZAYw literal 0 HcmV?d00001 diff --git a/sickbeard/providers/__init__.py b/sickbeard/providers/__init__.py index 89398b5b..5acbed3a 100755 --- a/sickbeard/providers/__init__.py +++ b/sickbeard/providers/__init__.py @@ -27,7 +27,7 @@ from sickbeard import logger, encodingKludge as ek from . import newznab, omgwtfnzbs # torrent from . import alpharatio, alphareign, beyondhd, bithdtv, bitmetv, blutopia, btn, btscene, dh, ettv, eztv, \ - fano, filelist, funfile, grabtheinfo, hdbits, hdme, hdspace, hdtorrents, immortalseed, \ + fano, filelist, funfile, grabtheinfo, hdbits, hdme, hdspace, hdtorrents, horriblesubs, immortalseed, \ iptorrents, limetorrents, magnetdl, morethan, nebulance, ncore, nyaa, pisexy, potuk, pretome, privatehd, ptf, \ rarbg, revtt, scenehd, scenetime, shazbat, showrss, skytorrents, speedcd, \ thepiratebay, torlock, torrentday, torrenting, torrentleech, \ @@ -62,6 +62,7 @@ __all__ = ['omgwtfnzbs', 'hdme', 'hdspace', 'hdtorrents', + 'horriblesubs', 'immortalseed', 'iptorrents', 'limetorrents', diff --git a/sickbeard/providers/horriblesubs.py b/sickbeard/providers/horriblesubs.py new file mode 100644 index 00000000..c0eabd50 --- /dev/null +++ b/sickbeard/providers/horriblesubs.py @@ -0,0 +1,96 @@ +# +# This file is part of SickGear. +# +# SickGear is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# SickGear is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SickGear. If not, see . + +import re +import traceback +import urllib + +from . import generic +from sickbeard import logger, show_name_helpers +from sickbeard.bs4_parser import BS4Parser +from lib.unidecode import unidecode + + +class HorribleSubsProvider(generic.TorrentProvider): + + def __init__(self): + generic.TorrentProvider.__init__(self, 'HorribleSubs', anime_only=True) + + self.url_base = 'http://horriblesubs.info/' + self.urls = {'config_provider_home_uri': self.url_base, + 'browse': self.url_base + 'lib/latest.php', + 'search': self.url_base + 'lib/search.php?value=%s'} + self.url = self.urls['config_provider_home_uri'] + + delattr(self, 'search_mode') + delattr(self, 'search_fallback') + + def _search_provider(self, search_params, **kwargs): + + results = [] + if self.show and not self.show.is_anime: + return results + + items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []} + + rc = dict((k, re.compile('(?i)' + v)) for (k, v) in { + 'info': 'dl-label', 'get': 'magnet:', 'nodots': '[\.\s]+'}.items()) + + for mode in search_params.keys(): + for search_string in search_params[mode]: + search_string = isinstance(search_string, unicode) and unidecode(search_string) or search_string + + search_url = self.urls['browse'] if 'Cache' == mode else \ + self.urls['search'] % rc['nodots'].sub(' ', search_string) + + html = self.get_url(search_url) + if self.should_skip(): + return results + + cnt = len(items[mode]) + try: + if not html or self._has_no_results(html): + raise generic.HaltParseException + + with BS4Parser(html, features=['html5lib', 'permissive']) as soup: + torrent_rows = soup.find_all('table', class_='release-table') + + if 1 > len(torrent_rows): + raise generic.HaltParseException + + for tr in torrent_rows: + if 4 < len(tr.find_all('td')): + try: + title = tr.find('td', class_='dl-label').get_text().strip() + title = title.startswith('[') and title or '[HorribleSubs] %s' % title + download_url = self._link(tr.find('a', href=rc['get'])['href']) + if title and download_url: + items[mode].append((title, download_url, '', '')) + except (AttributeError, TypeError, ValueError): + continue + + except generic.HaltParseException: + pass + except (StandardError, Exception): + logger.log(u'Failed to parse. Traceback: %s' % traceback.format_exc(), logger.ERROR) + self._log_search(mode, len(items[mode]) - cnt, search_url) + + results = self._sort_seeding(mode, results + items[mode]) + + return results + + +provider = HorribleSubsProvider() diff --git a/sickbeard/search.py b/sickbeard/search.py index 6538ddc7..bb4efcb8 100644 --- a/sickbeard/search.py +++ b/sickbeard/search.py @@ -628,7 +628,7 @@ def search_providers(show, episodes, manual_search=False, torrent_only=False, tr found_results[provider_id] = {} search_count = 0 - search_mode = cur_provider.search_mode + search_mode = getattr(cur_provider, 'search_mode', 'eponly') while True: search_count += 1 @@ -673,7 +673,7 @@ def search_providers(show, episodes, manual_search=False, torrent_only=False, tr found_results[provider_id][cur_ep] = search_results[cur_ep] break - elif not cur_provider.search_fallback or search_count == 2: + elif not getattr(cur_provider, 'search_fallback', False) or 2 == search_count: break search_mode = '%sonly' % ('ep', 'sp')['ep' in search_mode]