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

Feature/fix behondhd #7323

Merged
merged 6 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 19 additions & 8 deletions medusa/providers/generic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,25 @@ def add_cookies_from_ui(self):
return {'result': False,
'message': 'Cookie is not correctly formatted: {0}'.format(self.cookies)}

if not all(req_cookie in [x.rsplit('=', 1)[0] for x in self.cookies.split(';')]
for req_cookie in self.required_cookies):
return {
'result': False,
'message': "You haven't configured the requied cookies. Please login at {provider_url}, "
'and make sure you have copied the following cookies: {required_cookies!r}'
.format(provider_url=self.name, required_cookies=self.required_cookies)
}
if self.required_cookies:
if self.name != 'Beyond-HD':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now beyond-hd is the only one with a cookie name like: remember_web_59ba36addc2b2f9401580f01445acd8ea4e30af9d. So I had to make an exception for this provider.

if not all(req_cookie in [x.rsplit('=', 1)[0] for x in self.cookies.split(';')]
for req_cookie in self.required_cookies):
return {
'result': False,
'message': "You haven't configured the required cookies. Please login at {provider_url}, "
'and make sure you have copied the following cookies: {required_cookies!r}'
.format(provider_url=self.name, required_cookies=self.required_cookies)
}

elif not any('remember_web_' in x.rsplit('=', 1)[0] for x in self.cookies.split(';')):
return {
'result': False,
'message': "You haven't configured the required cookies. Please login at {provider_url}, "
'and make sure you have copied the following cookies: {required_cookies!r}'
.format(provider_url=self.name, required_cookies=self.required_cookies)
}


# cookie_validator got at least one cookie key/value pair, let's return success
add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
Expand Down
53 changes: 20 additions & 33 deletions medusa/providers/torrent/html/beyondhd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def __init__(self):
"""Initialize the class."""
super(BeyondHDProvider, self).__init__('Beyond-HD')

self.username = None
self.password = None
self.enable_cookies = True
self.cookies = ''
self.required_cookies = ('remember_web_[**long_hash**]',)

self.url = 'https://beyond-hd.me'
self.urls = {
Expand Down Expand Up @@ -99,7 +100,7 @@ def parse(self, data, mode):
items = []

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

# Continue only if one release is found
Expand All @@ -111,14 +112,17 @@ def parse(self, data, mode):
cells = result('td')

try:
link = cells[1].find('div')
if len(cells) < 2:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an hidden tr at the end with one td.

continue

link = cells[1].find('a')
download_url = urljoin(self.url, cells[2].find('a')['href'])
title = link.get_text(strip=True)
if not all([title, download_url]):
continue

seeders = int(cells[5].find('span').get_text())
leechers = int(cells[6].find('span').get_text())
seeders = int(cells[6].find('span').get_text())
leechers = int(cells[7].find('span').get_text())

# Filter unseeded torrent
if seeders < self.minseed:
Expand All @@ -128,10 +132,10 @@ def parse(self, data, mode):
title, seeders)
continue

torrent_size = cells[4].find('span').get_text()
torrent_size = cells[5].find('span').get_text()
size = convert_size(torrent_size, units=units) or -1

pubdate_raw = cells[3].find('span').get_text()
pubdate_raw = cells[4].find('span').get_text()
pubdate = self.parse_pubdate(pubdate_raw, human_time=True)

item = {
Expand All @@ -154,33 +158,16 @@ def parse(self, data, mode):

def login(self):
"""Login method used for logging in before doing search and torrent downloads."""
if any(dict_from_cookiejar(self.session.cookies).values()):
return True

if 'pass' in dict_from_cookiejar(self.session.cookies):
return True
return self.cookie_login('Login now')

login_html = self.session.get(self.urls['login'])
with BS4Parser(login_html.text, 'html5lib') as html:
token = html.find('input', attrs={'name': '_token'}).get('value')

login_params = {
'_token': token,
'username': self.username,
'password': self.password,
'remember': 'on',
}

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 'These credentials do not match our records.' in response.text:
log.warning('Invalid username or password. Check your settings')
return False
def check_required_cookies(self):
"""
Check if we have the required cookies in the requests sessions object.

return True
Meaning that we've already successfully authenticated once, and we don't need to go through this again.
Note! This doesn't mean the cookies are correct!
"""
return False


provider = BeyondHDProvider()