From 86e61035f87dbf99e4f952a906117168b070a81b Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 26 Apr 2019 17:09:15 +0200 Subject: [PATCH] Add nCore torrent provider (#6537) * Add nCore torrent provider * Small changes and fixes * rm ln * Fix snatching seasons when there aren't any single episode results * rename to ncore * Update CHANGELOG.md * don't use try_int --- CHANGELOG.md | 4 +- medusa/providers/__init__.py | 3 +- medusa/providers/torrent/__init__.py | 3 +- medusa/providers/torrent/json/bitcannon.py | 2 +- medusa/providers/torrent/json/ncore.py | 173 ++++++++++++++++++ medusa/providers/torrent/json/norbits.py | 2 +- medusa/search/core.py | 4 + .../slim/static/images/providers/ncore.png | Bin 0 -> 548 bytes themes/dark/assets/img/providers/ncore.png | Bin 0 -> 470 bytes themes/light/assets/img/providers/ncore.png | Bin 0 -> 470 bytes 10 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 medusa/providers/torrent/json/ncore.py create mode 100644 themes-default/slim/static/images/providers/ncore.png create mode 100644 themes/dark/assets/img/providers/ncore.png create mode 100644 themes/light/assets/img/providers/ncore.png diff --git a/CHANGELOG.md b/CHANGELOG.md index e3b4a085304..8744ccc8cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased #### New Features +- Added nCore torrent provider ([#6537](https://github.com/pymedusa/Medusa/pull/6537)) #### Improvements @@ -8,8 +9,10 @@ - Fixed lists not being saved when used with comma separated items ([#6428](https://github.com/pymedusa/Medusa/pull/6428)) - Fixed extra scripts running with Python 3 ([#6428](https://github.com/pymedusa/Medusa/pull/6428)) - Fixed Torrenting provider exception when offline ([#6430](https://github.com/pymedusa/Medusa/pull/6430)) +- Fixed not displaying quality preferred in show-header when configured ([#6455](https://github.com/pymedusa/Medusa/pull/6455)) - Fixed snatching of air by date shows specials ([#6457](https://github.com/pymedusa/Medusa/pull/6457)) - Fixed email notifier name parser warning for ABD episodes ([#6527](https://github.com/pymedusa/Medusa/pull/6527)) +- Fixed download of multi episode releases without single results ([#6537](https://github.com/pymedusa/Medusa/pull/6537)) ## 0.3.1 (2019-03-20) @@ -18,7 +21,6 @@ - Fixed sending Kodi notifications (Python 3) ([#6355](https://github.com/pymedusa/Medusa/pull/6355)) - Fixed sending Slack notifications (Python 3) ([#6355](https://github.com/pymedusa/Medusa/pull/6355)) - Fixed possible error while getting AniDB scene exceptions (Python 3) ([#6355](https://github.com/pymedusa/Medusa/pull/6355)) -- Fixed not displaying quality preferred in show-header when configured ([#6455](https://github.com/pymedusa/Medusa/pull/6455)) ----- diff --git a/medusa/providers/__init__.py b/medusa/providers/__init__.py index 4b5868250f6..31f15ea09ec 100644 --- a/medusa/providers/__init__.py +++ b/medusa/providers/__init__.py @@ -35,6 +35,7 @@ iptorrents, limetorrents, morethantv, + ncore, nebulance, norbits, nordicbits, @@ -66,7 +67,7 @@ 'speedcd', 'nyaa', 'torrentbytes', 'morethantv', 'tokyotoshokan', 'iptorrents', 'hebits', 'alpharatio', 'sdbits', 'shazbat', 'rarbg', 'tntvillage', 'binsearch', 'xthor', 'abnormal', 'scenetime', 'nebulance', 'tvchaosuk', 'bitcannon', 'torrentz2', 'pretome', 'anizb', - 'hdspace', 'nordicbits', 'danishbits', 'limetorrents', 'norbits', 'bithdtv', + 'hdspace', 'nordicbits', 'danishbits', 'limetorrents', 'norbits', 'bithdtv', 'ncore', 'zooqle', 'animebytes', 'animetorrents', 'anidex', 'shanaproject', 'torrenting', 'yggtorrent', 'elitetracker', 'archetorrent', 'privatehd', 'cinemaz', 'avistaz', 'bjshare' ] diff --git a/medusa/providers/torrent/__init__.py b/medusa/providers/torrent/__init__.py index 85745b1a519..0a61823b322 100644 --- a/medusa/providers/torrent/__init__.py +++ b/medusa/providers/torrent/__init__.py @@ -43,6 +43,7 @@ btn, danishbits, hdbits, + ncore, norbits, rarbg, torrentday, @@ -68,5 +69,5 @@ 'torrentbytes', 'torrentleech', 'nebulance', 'tvchaosuk', 'xthor', 'zooqle', 'bitcannon', 'btn', 'hdbits', 'norbits', 'rarbg', 'torrentday', 'nyaa', 'rsstorrent', 'shazbat', 'hebits', 'torrentz2', 'animetorrents', 'anidex', 'shanaproject', 'torrenting', 'yggtorrent', - 'elitetracker', 'privatehd', 'cinemaz', 'avistaz', 'bjshare' + 'elitetracker', 'privatehd', 'cinemaz', 'avistaz', 'bjshare', 'ncore' ] diff --git a/medusa/providers/torrent/json/bitcannon.py b/medusa/providers/torrent/json/bitcannon.py index 4763ccad858..252efae3dff 100644 --- a/medusa/providers/torrent/json/bitcannon.py +++ b/medusa/providers/torrent/json/bitcannon.py @@ -129,7 +129,7 @@ def parse(self, data, mode): title, seeders) continue - size = convert_size(row.pop('size', -1)) or -1 + size = convert_size(row.pop('size', None), default=-1) item = { 'title': title, diff --git a/medusa/providers/torrent/json/ncore.py b/medusa/providers/torrent/json/ncore.py new file mode 100644 index 00000000000..c698c64b245 --- /dev/null +++ b/medusa/providers/torrent/json/ncore.py @@ -0,0 +1,173 @@ +# coding=utf-8 + +"""Provider code for nCore.""" + +from __future__ import unicode_literals + +import logging + +from medusa import tv +from medusa.helper.common import convert_size +from medusa.logger.adapters.style import BraceAdapter +from medusa.providers.torrent.torrent_provider import TorrentProvider + +from requests.utils import dict_from_cookiejar + +log = BraceAdapter(logging.getLogger(__name__)) +log.logger.addHandler(logging.NullHandler()) + + +class NcoreProvider(TorrentProvider): + """nCore Torrent provider.""" + + def __init__(self): + """.Initialize the class.""" + super(NcoreProvider, self).__init__('nCore') + + # Credentials + self.username = None + self.password = None + + # URLs + self.url = 'https://ncore.cc' + self.urls = { + 'login': 'https://ncore.cc/login.php', + 'search': 'https://ncore.cc/torrents.php', + } + + # Proper Strings + self.proper_strings = ['PROPER', 'REPACK', 'REAL', 'RERIP'] + + # Miscellaneous Options + + # Cache + self.cache = tv.Cache(self, min_time=20) + + def search(self, search_strings, age=0, ep_obj=None, **kwargs): + """ + Search a provider and parse the results. + + :param search_strings: A dict with mode (key) and the search value (value) + :param age: Not used + :param ep_obj: Not used + :returns: A list of search results (structure) + """ + results = [] + if not self.login(): + return results + + categories = [ + 'xvidser_hun', 'xvidser', + 'dvdser_hun', 'dvdser', + 'hdser_hun', 'hdser' + ] + + # Search Params + search_params = { + 'nyit_sorozat_resz': 'true', + 'kivalasztott_tipus': ','.join(categories), + 'mire': '', + 'miben': 'name', + 'tipus': 'kivalasztottak_kozott', + 'searchedfrompotato': 'true', + 'jsons': 'true', + } + + for mode in search_strings: + log.debug('Search mode: {0}', mode) + + for search_string in search_strings[mode]: + + if mode != 'RSS': + log.debug('Search string: {search}', + {'search': search_string}) + + search_params['mire'] = search_string + + data = self.session.get_json(self.urls['search'], params=search_params) + if not data: + log.debug('No data returned from provider') + continue + + results += self.parse(data, mode) + + return results + + def parse(self, data, mode): + """ + Parse search results for items. + + :param data: The raw response from a search + :param mode: The current mode used to search, e.g. RSS + + :return: A list of items found + """ + items = [] + + torrent_rows = data.get('results', {}) + for row in torrent_rows: + try: + title = row.pop('release_name', '') + download_url = row.pop('download_url', '') + if not (title and download_url): + continue + + seeders = int(row.pop('seeders', 0)) + leechers = int(row.pop('leechers', 0)) + + # Filter unseeded torrent + if seeders < self.minseed: + if mode != 'RSS': + log.debug("Discarding torrent because it doesn't meet the" + ' minimum seeders: {0}. Seeders: {1}', + title, seeders) + continue + + size = convert_size(row.pop('size', None), default=-1) + + item = { + 'title': title, + 'link': download_url, + 'size': size, + 'seeders': seeders, + 'leechers': leechers, + 'pubdate': None, + } + if mode != 'RSS': + log.debug('Found result: {0} with {1} seeders and {2} leechers', + title, seeders, leechers) + + items.append(item) + except (AttributeError, TypeError, KeyError, ValueError, IndexError): + log.exception('Failed parsing provider.') + + return items + + def login(self): + """Login method used for logging in before doing search and torrent downloads.""" + if (dict_from_cookiejar(self.session.cookies).values() + and self.session.cookies.get('nick')): + return True + + login_params = { + 'nev': self.username, + 'pass': self.password, + 'ne_leptessen_ki': '1', + 'submitted': '1', + 'set_lang': 'en', + 'submit': 'Access!', + } + + response = self.session.post(self.urls['login'], data=login_params) + if not response or not response.text: + log.warning('Unable to connect to provider') + return False + + if 'Wrong username or password!' in response.text: + log.warning('Invalid username or password. Check your settings') + return False + + return True + + +provider = NcoreProvider() diff --git a/medusa/providers/torrent/json/norbits.py b/medusa/providers/torrent/json/norbits.py index cd273708b98..82ce3ba740f 100644 --- a/medusa/providers/torrent/json/norbits.py +++ b/medusa/providers/torrent/json/norbits.py @@ -125,7 +125,7 @@ def parse(self, data, mode): title, seeders) continue - size = convert_size(row.pop('size', -1), -1) + size = convert_size(row.pop('size', None), default=-1) item = { 'title': title, diff --git a/medusa/search/core.py b/medusa/search/core.py index 00528b42911..6b04b658b31 100644 --- a/medusa/search/core.py +++ b/medusa/search/core.py @@ -928,6 +928,10 @@ def combine_results(multi_results, single_results): log.debug(u'Adding {0} to multi-episode result candidates', candidate.name) result_candidates.append(candidate) + # If there aren't any single results we can return early + if not single_results: + return result_candidates + return_multi_results = [] for multi_result in result_candidates: # see how many of the eps that this result covers aren't covered by single results diff --git a/themes-default/slim/static/images/providers/ncore.png b/themes-default/slim/static/images/providers/ncore.png new file mode 100644 index 0000000000000000000000000000000000000000..ae2548bb5de1ab0243ccdf78101b674b1c2b7a84 GIT binary patch literal 548 zcmV+<0^9wGP)WFTUBAZ9~vWMy(7M{;3sXlY|} zAW(8|V`X!5Z*qUb?Oy-@0i8)iK~#9!jgvo50znkSNBJWvAyFYwN!0iS>}V|Mtc{(- z!Wat*trTNrWu*-?R#dh$cJd)COu){l5DRPogK*yAyt{X}5shr}gLk|0W@i^JxB*N8 zI44_V9;1yqDU!1wKQ5kteTT&inI_|^atv%@k(S3|6gXL;R19`L`LRqAWXfo^4Mfw^ z^#ExQ8tewS7@6aPPlWW1CLh^7r1O%p>FpDj1g@)G#5;K=Z@(DGuCv-Kb0|_9Q9fa$GIFHD-}1TV;cAuWa&b?*~C>oj~6z%kz+AzXEMlhZatmG0=!fM z1OI}$@Xr5Gt>U&+LR?MdyoqEIhuJJXRA-q6mKyXlL0?576?O3)+23p^LDvxa1|4|j zQrp^KQ>o2=s)ZODGtBvceoLaZ1RJ5yYpse7cRH~OaeG3TVx)ijXEikvmie%o`8La#SEDyG15_!ng9 zLc7_-RX&dwHo1{wF>Gft$a8KzoyG#ZR09M5g1Yd||4^;swp2n~P363aWDBvceoLaZ1RJ5yYpse7cRH~OaeG3TVx)ijXEikvmie%o`8La#SEDyG15_!ng9 zLc7_-RX&dwHo1{wF>Gft$a8KzoyG#ZR09M5g1Yd||4^;swp2n~P363aWD