Skip to content
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

Moved seeders sorting out of providers code and into the sickbeard/se… #658

Merged
merged 2 commits into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ def save_config(): # pylint: disable=too-many-statements, too-many-branches
new_config['Newznab']['newznab_data'] = NEWZNAB_DATA

new_config['TorrentRss'] = {}
new_config['TorrentRss']['torrentrss_data'] = '!!!'.join([x.configStr() for x in torrentRssProviderList])
new_config['TorrentRss']['torrentrss_data'] = '!!!'.join([x.config_string() for x in torrentRssProviderList])

new_config['GUI'] = {}
new_config['GUI']['gui_name'] = GUI_NAME
Expand Down
4 changes: 2 additions & 2 deletions sickbeard/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
omgwtfnzbs, scc, hdtorrents, torrentday, hdbits, hounddawgs, speedcd, nyaatorrents, bluetigers, xthor, abnormal, torrentbytes, cpasbien,\
freshontv, morethantv, t411, tokyotoshokan, shazbat, rarbg, alpharatio, tntvillage, binsearch, torrentproject, extratorrent, \
scenetime, btdigg, transmitthenet, tvchaosuk, bitcannon, pretome, gftracker, hdspace, newpct, elitetorrent, bitsnoop, danishbits, hd4free, limetorrents, \
norbits, ilovetorrents, sceneelite, anizb, bithdtv, zooqle
norbits, ilovetorrents, anizb, bithdtv, zooqle

__all__ = [
'womble', 'btn', 'thepiratebay', 'kat', 'torrentleech', 'scc', 'hdtorrents',
Expand All @@ -36,7 +36,7 @@
'xthor', 'abnormal', 'scenetime', 'btdigg', 'transmitthenet', 'tvchaosuk',
'torrentproject', 'extratorrent', 'bitcannon', 'torrentz', 'pretome', 'gftracker',
'hdspace', 'newpct', 'elitetorrent', 'bitsnoop', 'danishbits', 'hd4free', 'limetorrents',
'norbits', 'ilovetorrents', 'sceneelite', 'anizb', 'bithdtv', 'zooqle'
'norbits', 'ilovetorrents', 'anizb', 'bithdtv', 'zooqle'
]


Expand Down
121 changes: 75 additions & 46 deletions sickbeard/providers/abnormal.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# coding=utf-8
# Author: adaur <adaur.underground@gmail.com>
#

#
# This file is part of SickRage.
# This file is part of Medusa.
#
# SickRage is free software: you can redistribute it and/or modify
# Medusa 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,
# Medusa 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/>.
# along with Medusa. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import re
import traceback

from requests.compat import urljoin
from requests.utils import dict_from_cookiejar

Expand All @@ -32,7 +32,7 @@


class ABNormalProvider(TorrentProvider): # pylint: disable=too-many-instance-attributes

"""ABNormal Torrent provider"""
def __init__(self):

# Provider Init
Expand All @@ -42,10 +42,6 @@ def __init__(self):
self.username = None
self.password = None

# Torrent Stats
self.minseed = None
self.minleech = None

# URLs
self.url = 'https://abnormal.ws'
self.urls = {
Expand All @@ -56,66 +52,69 @@ def __init__(self):
# 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
# Miscellaneous Options

login_params = {
'username': self.username,
'password': self.password,
}

response = self.get_url(self.urls['login'], post_data=login_params, returns='text')
if not response:
logger.log('Unable to connect to provider', logger.WARNING)
return False

if not re.search('torrents.php', response):
logger.log('Invalid username or password. Check your settings', logger.WARNING)
return False
# Torrent Stats
self.minseed = None
self.minleech = None

return True
# Cache
self.cache = tvcache.TVCache(self, min_time=30)

def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-many-locals, too-many-branches
"""
ABNormal search and parsing

:param search_string: 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

# Search Params
search_params = {
'cat[]': ['TV|SD|VOSTFR', 'TV|HD|VOSTFR', 'TV|SD|VF', 'TV|HD|VF', 'TV|PACK|FR', 'TV|PACK|VOSTFR', 'TV|EMISSIONS', 'ANIME'],
# Both ASC and DESC are available for sort direction
'way': 'DESC'
'cat[]': [
'TV|SD|VOSTFR',
'TV|HD|VOSTFR',
'TV|SD|VF',
'TV|HD|VF',
'TV|PACK|FR',
'TV|PACK|VOSTFR',
'TV|EMISSIONS',
'ANIME',
],
'order': 'Time', # Sorting: Available parameters: ReleaseName, Seeders, Leechers, Snatched, Size
'way': 'DESC', # Both ASC and DESC are available for sort direction
}

# Units
units = ['O', 'KO', 'MO', 'GO', 'TO', 'PO']

for mode in search_strings:
items = []
logger.log('Search Mode: {}'.format(mode), logger.DEBUG)
logger.log('Search mode: {0}'.format(mode), logger.DEBUG)

for search_string in search_strings[mode]:

if mode != 'RSS':
logger.log('Search string: {}'.format(search_string.decode('utf-8')),
logger.DEBUG)
logger.log('Search string: {search}'.format
(search=search_string), logger.DEBUG)
search_params['order'] = 'Seeders'

# Sorting: Available parameters: ReleaseName, Seeders, Leechers, Snatched, Size
search_params['order'] = ('Seeders', 'Time')[mode == 'RSS']
search_params['search'] = re.sub(r'[()]', '', search_string)
data = self.get_url(self.urls['search'], params=search_params, returns='text')
if not data:
logger.log('No data returned from provider', logger.DEBUG)
continue

with BS4Parser(data, 'html5lib') as html:
torrent_table = html.find(class_='torrent_table')
torrent_rows = torrent_table('tr') if torrent_table else []

# Continue only if at least one Release is found
# 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
Expand All @@ -131,7 +130,8 @@ def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-man

try:
title = cells[labels.index('Release')].get_text(strip=True)
download_url = urljoin(self.url, cells[labels.index('DL')].find('a', class_='tooltip')['href'])
download = cells[labels.index('DL')].find('a', class_='tooltip')['href']
download_url = urljoin(self.url, download)
if not all([title, download_url]):
continue

Expand All @@ -141,28 +141,57 @@ def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-man
# Filter unseeded torrent
if seeders < min(self.minseed, 1):
if mode != 'RSS':
logger.log('Discarding torrent because it doesn\'t meet the minimum seeders: {0}. Seeders: {1})'.format
logger.log("Discarding torrent because it doesn't meet the "
"minimum seeders: {0}. Seeders: {1}".format
(title, seeders), logger.DEBUG)
continue

size_index = labels.index('Size') if 'Size' in labels else labels.index('Taille')
torrent_size = cells[size_index].get_text()
size = convert_size(torrent_size, units=units) or -1

item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'pubdate': None, 'hash': None}
item = {
'title': title,
'link': download_url,
'size': size,
'seeders': seeders,
'leechers': leechers,
'pubdate': None,
'hash': None,
}
if mode != 'RSS':
logger.log('Found result: {0} with {1} seeders and {2} leechers'.format
(title, seeders, leechers), logger.DEBUG)

items.append(item)
except StandardError:
except (AttributeError, TypeError, KeyError, ValueError, IndexError):
logger.log('Failed parsing provider. Traceback: {0!r}'.format
(traceback.format_exc()), logger.ERROR)
continue

# 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

def login(self):
if any(dict_from_cookiejar(self.session.cookies).values()):
return True

login_params = {
'username': self.username,
'password': self.password,
}

response = self.get_url(self.urls['login'], post_data=login_params, returns='text')
if not response:
logger.log('Unable to connect to provider', logger.WARNING)
return False

if not re.search('torrents.php', response):
logger.log('Invalid username or password. Check your settings', logger.WARNING)
return False

return True


provider = ABNormalProvider()
Loading