Private GIT

Skip to content
Snippets Groups Projects
Commit 0fef50ea authored by Mikkel's avatar Mikkel Committed by miigotu
Browse files

Danishbits provider now abides by their new rules, using couchpotato.php as...

Danishbits provider now abides by their new rules, using couchpotato.php as systems are not allowed to search torrents.php. (#3811)
parent 40cf9fa0
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@
from __future__ import print_function, unicode_literals
from requests.utils import dict_from_cookiejar
import json
from sickbeard import logger, tvcache
from sickbeard.bs4_parser import BS4Parser
......@@ -38,7 +38,7 @@ class DanishbitsProvider(TorrentProvider): # pylint: disable=too-many-instance-
# Credentials
self.username = None
self.password = None
self.passkey = None
# Torrent Stats
self.minseed = 0
......@@ -49,7 +49,7 @@ class DanishbitsProvider(TorrentProvider): # pylint: disable=too-many-instance-
self.url = 'https://danishbits.org/'
self.urls = {
'login': self.url + 'login.php',
'search': self.url + 'torrents.php',
'search': self.url + 'couchpotato.php',
}
# Proper Strings
......@@ -57,31 +57,6 @@ class DanishbitsProvider(TorrentProvider): # pylint: disable=too-many-instance-
# Cache
self.cache = tvcache.TVCache(self, min_time=10) # Only poll Danishbits every 10 minutes max
def login(self):
if any(dict_from_cookiejar(self.session.cookies).values()):
return True
login_params = {
'username': self.username.encode('utf-8'),
'password': self.password.encode('utf-8'),
'keeplogged': 1,
'langlang': '',
'login': 'Login',
}
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)
self.session.cookies.clear()
return False
if '<title>Login :: Danishbits.org</title>' in response:
logger.log("Invalid username or password. Check your settings", logger.WARNING)
self.session.cookies.clear()
return False
return True
def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-many-locals, too-many-branches
results = []
if not self.login():
......@@ -89,9 +64,9 @@ class DanishbitsProvider(TorrentProvider): # pylint: disable=too-many-instance-
# Search Params
search_params = {
'action': 'newbrowse',
'group': 3,
'search': '',
'user': self.username,
'passkey': self.passkey,
'search': search_strings,
}
# Units
......@@ -122,56 +97,28 @@ class DanishbitsProvider(TorrentProvider): # pylint: disable=too-many-instance-
logger.log("No data returned from provider", logger.DEBUG)
continue
with BS4Parser(data, 'html5lib') as html:
torrent_table = html.find('table', id='torrent_table')
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
# Literal: Navn, Størrelse, Kommentarer, Tilføjet, Snatches, Seeders, Leechers
# Translation: Name, Size, Comments, Added, Snatches, Seeders, Leechers
labels = [process_column_header(label) for label in torrent_rows[0]('td')]
# Skip column headers
for result in torrent_rows[1:]:
try:
title = result.find(class_='croptorrenttext').get_text(strip=True)
download_url = self.url + result.find(title="Direkte download link")['href']
if not all([title, download_url]):
continue
cells = result('td')
seeders = try_int(cells[labels.index('Seeders')].get_text(strip=True))
leechers = try_int(cells[labels.index('Leechers')].get_text(strip=True))
# Filter unseeded torrent
torrents = json.loads(data)
if 'results' in torrents:
for torrent in torrents['results']:
title = torrent['release_name']
download_url = torrent['download_url']
seeders = torrent['seeders']
leechers = torrent['leechers']
if seeders < self.minseed or leechers < self.minleech:
if mode != 'RSS':
logger.log("Discarding torrent because it doesn't meet the"
" minimum seeders or leechers: {0} (S:{1} L:{2})".format
(title, seeders, leechers), logger.DEBUG)
logger.log("Discarded {0} because with {1}/{2} seeders/leechers does not meet the requirement of {3}/{4} seeders/leechers".format(title, seeders, leechers, self.minseed, self.minleech))
continue
freeleech = result.find(class_='freeleech')
freeleech = torrent['freeleech']
if self.freeleech and not freeleech:
continue
torrent_size = cells[2].contents[0]
size = convert_size(torrent_size, units=units) or -1
item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''}
if mode != 'RSS':
size = torrent['size']
size = convert_size(size, units=units) or -1
item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders,
'leechers': leechers, 'hash': ''}
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment