Skip to content

Commit

Permalink
Add nCore torrent provider (pymedusa#6537)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
medariox authored and Thilas committed Jun 5, 2019
1 parent 29b02af commit 86e6103
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
## Unreleased

#### New Features
- Added nCore torrent provider ([#6537](https://github.com/pymedusa/Medusa/pull/6537))

#### Improvements

#### Fixes
- 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)

Expand All @@ -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))

-----

Expand Down
3 changes: 2 additions & 1 deletion medusa/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
iptorrents,
limetorrents,
morethantv,
ncore,
nebulance,
norbits,
nordicbits,
Expand Down Expand Up @@ -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'
]
Expand Down
3 changes: 2 additions & 1 deletion medusa/providers/torrent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
btn,
danishbits,
hdbits,
ncore,
norbits,
rarbg,
torrentday,
Expand All @@ -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'
]
2 changes: 1 addition & 1 deletion medusa/providers/torrent/json/bitcannon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
173 changes: 173 additions & 0 deletions medusa/providers/torrent/json/ncore.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion medusa/providers/torrent/json/norbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions medusa/search/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/dark/assets/img/providers/ncore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/light/assets/img/providers/ncore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 86e6103

Please sign in to comment.