-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add nCore torrent provider #6537
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fda2f78
Add nCore torrent provider
medariox 1263557
Small changes and fixes
medariox 14d0111
rm ln
medariox d8b4d6b
Fix snatching seasons when there aren't any single episode results
medariox fbc8415
rename to ncore
medariox 3b266c1
Update CHANGELOG.md
medariox dcfb3da
don't use try_int
medariox 0f70b38
Merge remote-tracking branch 'origin/feature/add-ncore' into feature/…
medariox 4b435af
Merge branch 'develop' into feature/add-ncore
medariox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove age and ep_obj. I don't think you need to put *args. The **kwargs should pick them up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just shadows how it is implemented in generic_provider. If we need to change it, we should change it for every other provider as well.