+class DramaFeverBaseIE(InfoExtractor):
+ _NETRC_MACHINE = 'dramafever'
+
+ _CONSUMER_SECRET = 'DA59dtVXYLxajktV'
+
+ _consumer_secret = None
+
+ def _get_consumer_secret(self):
+ mainjs = self._download_webpage(
+ 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
+ None, 'Downloading main.js', fatal=False)
+ if not mainjs:
+ return self._CONSUMER_SECRET
+ return self._search_regex(
+ r"var\s+cs\s*=\s*'([^']+)'", mainjs,
+ 'consumer secret', default=self._CONSUMER_SECRET)
+
+ def _real_initialize(self):
+ self._consumer_secret = self._get_consumer_secret()
+ self._login()
+
+ def _login(self):
+ (username, password) = self._get_login_info()
+ if username is None:
+ return
+
+ login_form = {
+ 'username': username,
+ 'password': password,
+ }
+
+ try:
+ response = self._download_json(
+ 'https://www.dramafever.com/api/users/login', None, 'Logging in',
+ data=json.dumps(login_form).encode('utf-8'), headers={
+ 'x-consumer-key': self._consumer_secret,
+ })
+ except ExtractorError as e:
+ if isinstance(e.cause, compat_HTTPError) and e.cause.code in (403, 404):
+ response = self._parse_json(
+ e.cause.read().decode('utf-8'), None)
+ else:
+ raise
+
+ # Successful login
+ if response.get('result') or response.get('guid') or response.get('user_guid'):
+ return
+
+ errors = response.get('errors')
+ if errors and isinstance(errors, list):
+ error = errors[0]
+ message = error.get('message') or error['reason']
+ raise ExtractorError('Unable to login: %s' % message, expected=True)
+ raise ExtractorError('Unable to log in')
+
+
+class DramaFeverIE(DramaFeverBaseIE):