11 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #youtube_dl/extractor/iqiyi.py: Login function, invoking non-free client side authentication algorithm
  2. #ln=
  3. def _login(self):
  4. (username, password) = self._get_login_info()
  5. # No authentication to be performed
  6. if not username:
  7. return True
  8. data = self._download_json(
  9. 'http://kylin.iqiyi.com/get_token', None,
  10. note='Get token for logging', errnote='Unable to get token for logging')
  11. sdk = data['sdk']
  12. timestamp = int(time.time())
  13. target = '/apis/reglogin/login.action?lang=zh_TW&area_code=null&email=%s&passwd=%s&agenttype=1&from=undefined&keeplogin=0&piccode=&fromurl=&_pos=1' % (
  14. username, self._rsa_fun(password.encode('utf-8')))
  15. interp = IqiyiSDKInterpreter(sdk)
  16. sign = interp.run(target, data['ip'], timestamp)
  17. validation_params = {
  18. 'target': target,
  19. 'server': 'BEA3AA1908656AABCCFF76582C4C6660',
  20. 'token': data['token'],
  21. 'bird_src': 'f8d91d57af224da7893dd397d52d811a',
  22. 'sign': sign,
  23. 'bird_t': timestamp,
  24. }
  25. validation_result = self._download_json(
  26. 'http://kylin.iqiyi.com/validate?' + compat_urllib_parse_urlencode(validation_params), None,
  27. note='Validate credentials', errnote='Unable to validate credentials')
  28. MSG_MAP = {
  29. 'P00107': 'please login via the web interface and enter the CAPTCHA code',
  30. 'P00117': 'bad username or password',
  31. }
  32. code = validation_result['code']
  33. if code != 'A00000':
  34. msg = MSG_MAP.get(code)
  35. if not msg:
  36. msg = 'error %s' % code
  37. if validation_result.get('msg'):
  38. msg += ': ' + validation_result['msg']
  39. self._downloader.report_warning('unable to log in: ' + msg)
  40. return False
  41. return True