Skip to content

Commit

Permalink
Merge pull request #1085 from SickRage/tvchaos_tntv
Browse files Browse the repository at this point in the history
Fix tvchaos and tntvillage logins
  • Loading branch information
miigotu committed Feb 28, 2016
2 parents b94d78a + 2505409 commit e8bcc38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sickbeard/providers/tntvillage.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def _check_auth(self):
return True

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

login_params = {'UserName': self.username,
'PassWord': self.password,
'CookieDate': 0,
'CookieDate': 1,
'submit': 'Connettiti al Forum'}

response = self.get_url(self.urls['login'], post_data=login_params, timeout=30)
Expand Down
16 changes: 14 additions & 2 deletions sickbeard/providers/tvchaosuk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.

import re
import time
from requests.utils import dict_from_cookiejar

from sickbeard import logger, tvcache
Expand Down Expand Up @@ -65,7 +66,9 @@ def _check_auth(self):
raise AuthException('Your authentication credentials for ' + self.name + ' are missing, check your config.')

def login(self):
if any(dict_from_cookiejar(self.session.cookies).values()):
# cloudflare leaves __cfduid cookie even if cookie is expired,
# there are 4 cookies when cookie is valid
if len(dict_from_cookiejar(self.session.cookies)) == 4:
return True

login_params = {
Expand All @@ -77,12 +80,21 @@ def login(self):
}

# Must be done twice, or it isnt really logged in
response = self.get_url(self.urls['login'], post_data=login_params, timeout=30)
# first time gets __cfduid, if we already have __cfduid this might get the cookie
response = self.get_url(self.urls['login'], post_data=login_params, timeout=30)
if not response:
logger.log(u"Unable to connect to provider", logger.WARNING)
return False

# if the first post only got the __cfduid then sleep 5 seconds for cloudflare anti-bot
# and then get the actual cookie
if len(dict_from_cookiejar(self.session.cookies)) < 4:
time.sleep(5)
response = self.get_url(self.urls['login'], post_data=login_params, timeout=30)
if not response:
logger.log(u"Unable to connect to provider", logger.WARNING)
return False

if re.search('Error: Username or password incorrect!', response):
logger.log(u"Invalid username or password. Check your settings", logger.WARNING)
return False
Expand Down

0 comments on commit e8bcc38

Please sign in to comment.