From 6097457aca5544287eacd985550cca38d9c90cdc Mon Sep 17 00:00:00 2001 From: adaur <adaur@users.noreply.github.com> Date: Sun, 24 Sep 2017 23:40:58 -0400 Subject: [PATCH] Add provider YggTorrent (#3963) * Add provider YggTorrent * Fix connection method + leechers / seeders values (#4034) --- gui/slick/images/providers/yggtorrent.png | Bin 0 -> 2150 bytes sickbeard/providers/__init__.py | 4 +- sickbeard/providers/yggtorrent.py | 151 ++++++++++++++++++++++ 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 gui/slick/images/providers/yggtorrent.png create mode 100644 sickbeard/providers/yggtorrent.py diff --git a/gui/slick/images/providers/yggtorrent.png b/gui/slick/images/providers/yggtorrent.png new file mode 100644 index 0000000000000000000000000000000000000000..de04ec0b111250b9610fd5fb2d26c8435c487057 GIT binary patch literal 2150 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANMEx}GkMArY-xr)3vNUll!G zzdLH}lBqi0o1TUz-MrD4`{+ug)kfhHvzdau4BvjxxZEf<gU2WRQr!!lzfSGjG>uzl z`n1iQc72I%NswHo^Fmb{pWy3^LTX3M6hq3Mgy)=|IDgZU*pu3C^Xx4WGhQ8;a^P>t zd)w-B|F?giSN*QlH7YkZ_u{*|yT8XuOrJK*>ifI9xA!I;?K*X|#@=68{CC3ZYis>E z14<KZ%*>{}eEXJnecaw(6W7Zu*t_@c_BG3%J==c!*0-9ne?LAx)?XL3^HbaM`E^wn z<##AGY}&L*>-450GiT1+tT)|z<@)vUd>w6xFDff5UG=7)u3XA+>1of+oUmY#*0ZzC z?FBzPHD4Bda+a@jbll1nE7qJ(+q}#7`q%X$2?+@bmoDG7zIpX#W%lP?rWv!2UHNcA zch$6IJ9hk-|NGn9)3KTjZ;OsGv-8d9T69Bo_KwAgKZ`<4TW9$R&z_+m)Okm~`{=Lr zA_*5&tg61ecq|=d*5`hHuJXJ~E7q)1yZ`#HZ+Ut7?WtXdm7*CEB;5Sw&;1yAGSX{r zp4%_w8BG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OH4Lc-}zF1$My1dd8MLN-D{qvY1GX6b0MlI$<En!x#o&2x9xXoKC9QKoVMMsGPTX) zdG%*)1&$ZXxZ5Yib13B8*%5ea@9W>PJCC#&nPg9RF5olYS)g5L+RNgGaIqtsJx@<b z5${^hQJThc+2Dg%XveEFmcbvz7A>EA;?y7K$m>EUy23?Tek#qrYN~RxRjmKv8SVvs puD+@PY0q}2zMXmBZsS|~$3K<_`hR=Y#K6G7;OXk;vd$@?2>`UTMC<?n literal 0 HcmV?d00001 diff --git a/sickbeard/providers/__init__.py b/sickbeard/providers/__init__.py index cdd98b9ee..1f3906080 100644 --- a/sickbeard/providers/__init__.py +++ b/sickbeard/providers/__init__.py @@ -28,7 +28,7 @@ from sickbeard.providers import (abnormal, alpharatio, archetorrent, binsearch, hd4free, hdbits, hdspace, hdtorrents, hdtorrents_it, horriblesubs, hounddawgs, ilcorsaronero, immortalseed, iptorrents, limetorrents, morethantv, ncore, nebulance, newpct, norbits, nyaa, omgwtfnzbs, pretome, rarbg, scc, scenetime, shazbat, skytorrents, speedcd, thepiratebay, tntvillage, tokyotoshokan, torrent9, torrentbytes, torrentday, torrentleech, - torrentproject, torrentz, tvchaosuk, xthor) + torrentproject, torrentz, tvchaosuk, xthor, yggtorrent) __all__ = [ 'abnormal', 'alpharatio', 'archetorrent', 'binsearch', 'bitcannon', 'btn', 'cpasbien', 'danishbits', @@ -36,7 +36,7 @@ __all__ = [ 'horriblesubs', 'hounddawgs', 'ilcorsaronero', 'immortalseed', 'iptorrents', 'limetorrents', 'morethantv', 'ncore', 'nebulance', 'newpct', 'norbits', 'nyaa', 'omgwtfnzbs', 'pretome', 'rarbg', 'scc', 'scenetime', 'shazbat', 'skytorrents', 'speedcd', 'thepiratebay', 'tntvillage', 'tokyotoshokan', 'torrent9', - 'torrentbytes', 'torrentday', 'torrentleech', 'torrentproject', 'torrentz', 'tvchaosuk', 'xthor' + 'torrentbytes', 'torrentday', 'torrentleech', 'torrentproject', 'torrentz', 'tvchaosuk', 'xthor', 'yggtorrent' ] diff --git a/sickbeard/providers/yggtorrent.py b/sickbeard/providers/yggtorrent.py new file mode 100644 index 000000000..c76533bdc --- /dev/null +++ b/sickbeard/providers/yggtorrent.py @@ -0,0 +1,151 @@ +# coding=utf-8 +# Author: adaur <adaur.underground@gmail.com> +# +# URL: https://sickrage.github.io +# +# This file is part of SickRage. +# +# SickRage 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. +# +# SickRage 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 SickRage. If not, see <http://www.gnu.org/licenses/>. + +from __future__ import unicode_literals + +import re + +from requests.compat import urljoin +from requests.utils import dict_from_cookiejar + +from sickbeard import logger, tvcache +from sickbeard.bs4_parser import BS4Parser +from sickrage.helper.common import convert_size, try_int +from sickrage.providers.torrent.TorrentProvider import TorrentProvider + + +class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance-attributes + + def __init__(self): + + # Provider Init + TorrentProvider.__init__(self, 'YggTorrent') + + # Credentials + self.username = None + self.password = None + + # Torrent Stats + self.minseed = None + self.minleech = None + + # URLs + self.url = 'https://yggtorrent.com/' + self.urls = { + 'login': urljoin(self.url, 'user/login'), + 'search': urljoin(self.url, 'engine/search'), + } + + # Proper Strings + self.proper_strings = ['PROPER'] + + # Cache + self.cache = tvcache.TVCache(self, min_time=30) + + def login(self): + if any(dict_from_cookiejar(self.session.cookies).values()): + return True + + login_params = { + 'id': self.username, + 'pass': self.password, + } + + response = self.get_url(self.urls['login'], post_data=login_params, returns='text') + if response: # Yggtorrent return empty response if user is logged, so ... + logger.log('Invalid username or password. Check your settings', logger.WARNING) + return False + + return True + + def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-many-locals, too-many-branches + results = [] + if not self.login(): + return results + + for mode in search_strings: + items = [] + logger.log('Search Mode: {0}'.format(mode), logger.DEBUG) + + for search_string in search_strings[mode]: + + if mode != 'RSS': + logger.log('Search string: {0}'.format + (search_string.decode('utf-8')), logger.DEBUG) + + try: + search_params = { + 'q': re.sub(r'[()]', '', search_string) + } + data = self.get_url(self.urls['search'], params=search_params, returns='text') + if not data: + continue + + with BS4Parser(data, 'html5lib') as html: + torrent_table = html.find(class_='table table-striped') + torrent_rows = torrent_table('tr') if torrent_table else [] + + # Continue only if at least one Release is found + if len(torrent_rows) < 2: + logger.log('Data returned from provider does not contain any torrents', logger.DEBUG) + continue + + # Skip column headers + for result in torrent_rows[1:]: + cells = result('td') + if len(cells) < 5: + continue + + title = cells[0].find('a', class_='torrent-name').get_text(strip=True) + download_url = urljoin(self.url, cells[0].find('a', target='_blank')['href']) + if not (title and download_url): + continue + + seeders = try_int(cells[4].get_text(strip=True)) + leechers = try_int(cells[5].get_text(strip=True)) + + torrent_size = cells[2].get_text() + size = convert_size(torrent_size) or -1 + + # Filter unseeded torrent + if seeders < self.minseed or leechers < self.minleech: + if mode != 'RSS': + logger.log('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': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} + if mode != 'RSS': + logger.log('Found result: {0} with {1} seeders and {2} leechers'.format + (title, seeders, leechers), logger.DEBUG) + + items.append(item) + + except (AttributeError, TypeError, KeyError, ValueError): + logger.log('Failed parsing provider {}.'.format(self.name), logger.ERROR) + + # For each search mode sort all the items by seeders if available + items.sort(key=lambda d: try_int(d.get('seeders', 0)), reverse=True) + results += items + + return results + + +provider = YggTorrentProvider() -- GitLab