From 2bb391cdf9fc2a6e690bae8e1547459e104979b9 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Sat, 13 May 2017 21:51:55 +0100 Subject: [PATCH] Add Nyaa (.si) torrent provider. --- CHANGES.md | 1 + gui/slick/images/providers/nyaa.png | Bin 0 -> 770 bytes sickbeard/providers/__init__.py | 3 +- sickbeard/providers/nyaa.py | 101 ++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 gui/slick/images/providers/nyaa.png create mode 100644 sickbeard/providers/nyaa.py diff --git a/CHANGES.md b/CHANGES.md index ace4aeeb..bd0ddcef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -52,6 +52,7 @@ * Add Skytorrents torrent provider * Change do not have shows checked by default on import page. To re-enable import shows checked by default, 1) On config page 'Save' 2) Stop SG 3) Find 'import_default_checked_shows' in config.ini and set '1' 4) Start SG +* Add Nyaa (.si) torrent provider [develop changelog] diff --git a/gui/slick/images/providers/nyaa.png b/gui/slick/images/providers/nyaa.png new file mode 100644 index 0000000000000000000000000000000000000000..5f3b2c378bec885272447c116fc462e38b54fd99 GIT binary patch literal 770 zcmV+d1O5DoP)Bc>H3N!4L!rA^|B9p>=~qqyP;KH4Q(328n_aiJB6L209uV zBnl*oBvl}!h%y0#i4~8X@x1Qqobypkz4xm2+Om1;Yc=Z!RCR-h0DwS@fGTTkfy^?v z-k}~9JbX})cMYzaQk^`(b#`8+**(NB=NMy9U4d;Y^!D5IcQeXG*5ADLy|#n=^+iom@+!Ehy~*z9%(AY7{MArQ97AWmBPK#j1OOe7uF1)zYUWrV$`yp!B;cE zH4!AP22dbRVA;UgMZlg$!tdVKW!%iz(Ht z!=z3KUP&Dkjk1%&t6jwbG(ow2J>#N;2ge?-7UzVc^T^;*!u!|S{Q6g5JC77zI6N=_ zJemlu^pTqb%eS9wk|c&7?pFNxyJu3vM>kSl-?I#R24@wG@ZTcx-TlD5f8duVH7+hJ zpB`?JXR9NA{7%ln9=vrKatluvu-{o_Cj}%5-`|;W_dF+S=QvmX&7I$V=J?^NR5Z%t z)4;WXqxLW@BmJ&nRw+l5$lki4c)X+;C+K9v{~L`>p(. + +import re +import traceback + +from . import generic +from sickbeard import logger, show_name_helpers +from sickbeard.bs4_parser import BS4Parser +from sickbeard.helpers import tryInt +from lib.unidecode import unidecode + + +class NyaaProvider(generic.TorrentProvider): + + def __init__(self): + generic.TorrentProvider.__init__(self, 'Nyaa', anime_only=True) + + self.url_base = 'https://www.nyaa.si/' + self.urls = {'config_provider_home_uri': self.url_base, 'search': self.url_base + '?f=%s&c=1_0&q=%s'} + + self.url = self.urls['config_provider_home_uri'] + + self.minseed, self.minleech = 2 * [None] + self.confirmed = False + + 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': 'view', 'get': '(?:torrent|magnet:)'}.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['search'] % ((0, 2)[self.confirmed], search_string) + + html = self.get_url(search_url) + + 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_table = soup.find('table', class_='torrent-list') + torrent_rows = [] if not torrent_table else torrent_table.find_all('tr') + + if 2 > len(torrent_rows): + raise generic.HaltParseException + + head = None + for tr in torrent_rows[1:]: + cells = tr.find_all('td') + if 5 > len(cells): + continue + try: + head = head if None is not head else self._header_row(tr) + seeders, leechers, size = [tryInt(n, n) for n in [ + cells[head[x]].get_text().strip() for x in 'seed', 'leech', 'size']] + if self._peers_fail(mode, seeders, leechers): + continue + + title = tr.find('a', href=rc['info']).get_text().strip() + download_url = self._link(tr.find('a', href=rc['get'])['href']) + except (AttributeError, TypeError, ValueError, IndexError): + continue + + if title and download_url: + items[mode].append((title, download_url, seeders, self._bytesizer(size))) + + 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 = NyaaProvider()