einstein95 / crunchy-xml-decoder

GNU General Public License v2.0
35 stars 14 forks source link

Can't login #63

Open Flwk opened 8 years ago

Flwk commented 8 years ago

Hello

I have an a premium account, but when i want to connect with the script i have this error : screenshot_1

What is the problem ?

Many Thanks

danny-ml commented 8 years ago

https://github.com/einstein95/crunchy-xml-decoder/issues/50#issuecomment-170406596

Flwk commented 8 years ago

Hello @danny-ml

The fix of the #50 doesn't work now.

What's the problem @einstein95 ?

Many thanks in advance

iCertys commented 8 years ago

Change login.py line 20

old: site = session.get('https://www.crunchyroll.com/acct/membership/', headers=headers, verify=True).text

new: site = session.get('https://www.crunchyroll.com/acct/membership', headers=headers, verify=True).text

iCertys commented 8 years ago

The URL https://www.crunchyroll.com/acct/membership/ isn't working (404)

but without the "/" on the end it works

(sorry for my bad english)

Regards iCerty's

johnfigs commented 8 years ago

Hello, I changed line 20 and still receive 'Login failed'. I am currently on a trial, will I be able to log-in after the trial period?

iCertys commented 8 years ago

I don't have a Trail Accont so I can't Test this. But there is one thing that you can check. Open your Browser and go to https://www.crunchyroll.com/acct/membership

Then view the SourceCode and search for dimension5

You should find something like this ga('set', 'dimension5', 'registered');

In the 'registered'); part is different send me this part and I will try to write a Fix for you.

Sorry for my bad english!

iCertys commented 8 years ago

*If the 'reg...

johnfigs commented 8 years ago

iCertys, your english is very good! I looked at the source code and see the following:

ga('set', 'dimension5', 'freetrial'); ga('set', 'dimension6', 'premium');

Let me know if this is enough info. Thanks.

iCertys commented 8 years ago

Replace the entire code in login.py with these `import sys import re import requests import pickle from getpass import getpass

def getuserstatus(session=''): status = 'Guest' user1 = 'Guest' if session == '': session = requests.session() with open('cookies') as f: cookies = requests.utils.cookiejar_from_dict(pickle.load(f)) session = requests.session() session.cookies = cookies del session.cookies['c_visitor']

print session.cookies #session = requests.session()

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
           'Connection': 'keep-alive'}
site = session.get('https://www.crunchyroll.com/acct/membership', headers=headers, verify=True).text
#open('tempfile','w').write(site).encoding('UTF-8')
#print site.encode('utf-8')
if re.search(re.escape('      ga(\'set\', \'dimension5\', \'registered\');'), site):
    status = 'Free Member'
elif re.search(re.escape('      ga(\'set\', \'dimension5\', \'premium\');'), site):
    if re.search(re.escape('      ga(\'set\', \'dimension6\', \'premiumplus\');'), site):
        status = 'Premium+ Member'
    else:
        status = 'Premium Member'
elif re.search(re.escape('      ga(\'set\', \'dimension5\', \'freetrail\');'), site):
        status = 'Premium Member'
if status != 'Guest':
    user1 = re.findall('<a href=\"/user/(.+)\" ', site).pop()
return [status,user1]

def login(username, password): headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0', 'Connection': 'keep-alive'} session = requests.session() session.get('http://www.crunchyroll.com/', headers=headers)

headers = {'Referer': 'https://www.crunchyroll.com/login',
           'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
           'Content-Type': 'application/x-www-form-urlencoded'}

payload = {'formname': 'RpcApiUser_Login', 'fail_url': 'http://www.crunchyroll.com/login',
           'name': username, 'password': password}
res = session.post('https://www.crunchyroll.com/?a=formhandler', data=payload, headers=headers).text
for c in session.cookies:
    c.expires = 9999999999  # Saturday, November 20th 2286, 17:46:39 (GMT)

del session.cookies['c_visitor']
del session.cookies['sess_id']

#headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
#           'Connection': 'keep-alive'}
#url = 'http://www.crunchyroll.com/'
#site = session.get(url, headers=headers).text
#print session.get('https://www.crunchyroll.com/acct/membership/', headers=headers, verify=True).text.encode('utf-8')
#print getuserstatus(session)
#if re.search(username+'(?i)', site):
#    if username == '':
#        print 'Login as Guest.'
#    else:
#        print 'Login successful.'
#    pickle.dump(requests.utils.dict_from_cookiejar(session.cookies), open('cookies', 'w'))
#    with open('cookies', 'w') as f:
#        pickle.dump(requests.utils.dict_from_cookiejar(session.cookies), f)
#else:
#    print 'Login failed.'
#    sys.exit()
userstatus = getuserstatus(session)
if username != '' and userstatus[1] == 'Guest':
    print 'Login failed.'
    sys.exit()
else:
    print 'Login as '+userstatus[0]+' successfully.'
    pickle.dump(requests.utils.dict_from_cookiejar(session.cookies), open('cookies', 'w'))
    with open('cookies', 'w') as f:
        pickle.dump(requests.utils.dict_from_cookiejar(session.cookies), f) 

if name == 'main': try: if sys.argv[1][0] == 'y': username = raw_input(u'Username: ') password = getpass('Password(don\'t worry the password are typing but hidden:') except IndexError: username = '' password = '' login(username, password)`

iCertys commented 8 years ago

with out the ` at the start and at the end. I don't know why they are there.

If you are interested in what I have changed, i added this after line 29:

elif re.search(re.escape(' ga(\'set\', \'dimension5\', \'freetrail\');'), site): status = 'Premium Member'

johnfigs commented 8 years ago

that worked by changing the line to 'elif re.search(re.escape(' ga(\'set\', \'dimension5\', \'freetrail\');'), site): status = 'Premium Member''

Thank You!

Dokman commented 8 years ago

not work in my case, what line i have to change? :(

iCertys commented 8 years ago

@Dokman can you please Post your error Output and Information about Premium or Premium+ or Free or Trail or DayPass Member.

jsonn commented 8 years ago

78 includes the changes for dealing with the new login mechanism. I haven't tried non-premium, so YMMV.