Skip to content

Commit

Permalink
Get speed.cd login URL instead of looping a list of URLs (#3497)
Browse files Browse the repository at this point in the history
* Get speed.cd login URL instead of looping a list of URLs

* Review

* Review
  • Loading branch information
fernandog authored Dec 19, 2017
1 parent 928ba47 commit bb771f3
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions medusa/providers/torrent/html/speedcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import unicode_literals

import logging
import re
import traceback

from medusa import tv
Expand Down Expand Up @@ -38,11 +37,9 @@ def __init__(self):
# URLs
self.url = 'https://speed.cd'
self.urls = {
'login': [urljoin(self.url, 'take_login.php'),
urljoin(self.url, 'takeElogin.php'),
urljoin(self.url, 'takelogin.php')
],
'login': urljoin(self.url, 'login.php'),
'search': urljoin(self.url, 'browse.php'),
'login_post': None,
}

# Proper Strings
Expand Down Expand Up @@ -183,20 +180,34 @@ def login(self):
'password': self.password,
}

for login_url in self.urls['login']:
response = self.session.post(login_url, data=login_params)
if not response or not response.text:
log.debug('Unable to connect to provider using login URL: {url}',
{'url': login_url})
continue
if not (self.urls['login_post'] and self.login_url()):
log.debug('Unable to get login URL')
return False

if re.search('Incorrect username or Password. Please try again.', response.text):
log.warning('Invalid username or password. Check your settings')
return False
return True
response = self.session.post(self.urls['login_post'], data=login_params)
if not response or not response.text:
log.debug('Unable to connect to provider using login URL: {url}',
{'url': self.urls['login_post']})
return False
if 'incorrect username or password. please try again' in response.text.lower():
log.warning('Invalid username or password. Check your settings')
return False
return True

log.warning('Unable to connect to provider')
return

def login_url(self):
"""Get the login url (post) as speed.cd keeps changing it."""
response = self.session.get(self.urls['login'])
if not response or not response.text:
log.debug('Unable to connect to provider to get login URL')
return
data = BS4Parser(response.text, 'html5lib')
login_post = data.soup.find('form', id='loginform').get('action')
if login_post:
self.urls['login_post'] = urljoin(self.url, login_post)
return True


provider = SpeedCDProvider()

0 comments on commit bb771f3

Please sign in to comment.