-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,152 @@ | ||
# coding=utf-8 | ||
# Author: medariox <dariox@gmx.com> | ||
# | ||
# This file is part of Medusa. | ||
# | ||
# 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. | ||
# | ||
# 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 Medusa. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import unicode_literals | ||
|
||
from requests.compat import urljoin | ||
|
||
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 ZooqleProvider(TorrentProvider): # pylint: disable=too-many-instance-attributes | ||
"""Zooqle Torrent provider""" | ||
def __init__(self): | ||
|
||
# Provider Init | ||
TorrentProvider.__init__(self, 'Zooqle') | ||
|
||
# Credentials | ||
self.public = True | ||
|
||
# Torrent Stats | ||
self.minseed = None | ||
self.minleech = None | ||
|
||
# URLs | ||
self.url = 'https://zooqle.com/' | ||
self.urls = { | ||
'search': urljoin(self.url, '/search'), | ||
} | ||
|
||
# Proper Strings | ||
self.proper_strings = ['PROPER', 'REPACK', 'REAL'] | ||
|
||
# Cache | ||
self.cache = tvcache.TVCache(self, min_time=15) | ||
|
||
def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-many-locals, too-many-branches | ||
""" | ||
Zooqle 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 = [] | ||
|
||
# Search Params | ||
search_params = { | ||
'q': '* category:TV', | ||
's': 'dt', | ||
'v': 't', | ||
'sd': 'd', | ||
} | ||
|
||
# Units | ||
units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] | ||
|
||
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': | ||
search_params = {'q': '{0}+category:TV'.format(search_strings)} | ||
|
||
response = self.get_url(self.urls['search'], params=search_params, returns='response') | ||
if not response.text: | ||
logger.log('No data returned from provider', logger.DEBUG) | ||
continue | ||
|
||
with BS4Parser(response.text, 'html5lib') as html: | ||
torrent_table = html.find('div', class_='panel-body') | ||
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:]: | ||
|
||
try: | ||
cells = result('td') | ||
|
||
title = cells[1].find('a').get_text() | ||
download_url = cells[2].find('a')['href'] | ||
if not all([title, download_url]): | ||
continue | ||
|
||
peers = cells[6].find('div')['title'].replace(',', '').split(' | ', 1) | ||
seeders = try_int(peers[0].strip('Seeders: ')) | ||
leechers = try_int(peers[1].strip('Leechers: ')) | ||
|
||
# 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 | ||
(title, seeders), logger.DEBUG) | ||
continue | ||
|
||
torrent_size = cells[4].get_text(strip=True) | ||
|
||
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 | ||
} | ||
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: | ||
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 | ||
|
||
|
||
provider = ZooqleProvider() |