Extract login logic shared by Medialaan and VrtNU to GigyaBase

This commit is contained in:
mrBliss 2017-10-24 14:08:44 +02:00
parent c98d241de2
commit 5ed058f247
3 changed files with 32 additions and 25 deletions

View File

@ -3,7 +3,11 @@ from __future__ import unicode_literals
import re import re
import json import json
from .common import InfoExtractor from .common import (
InfoExtractor,
GigyaBaseIE,
)
from ..compat import compat_HTTPError from ..compat import compat_HTTPError
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
@ -11,7 +15,6 @@ from ..utils import (
float_or_none, float_or_none,
int_or_none, int_or_none,
parse_iso8601, parse_iso8601,
urlencode_postdata,
) )
@ -174,7 +177,7 @@ class CanvasEenIE(InfoExtractor):
} }
class VrtNUIE(InfoExtractor): class VrtNUIE(GigyaBaseIE):
IE_DESC = 'VrtNU.be' IE_DESC = 'VrtNU.be'
_VALID_URL = r'https?://(?:www\.)?vrt\.be/(?P<site_id>vrtnu)/(?:[^/]+/)*(?P<id>[^/?#&]+)' _VALID_URL = r'https?://(?:www\.)?vrt\.be/(?P<site_id>vrtnu)/(?:[^/]+/)*(?P<id>[^/?#&]+)'
_TESTS = [{ _TESTS = [{
@ -212,15 +215,7 @@ class VrtNUIE(InfoExtractor):
'authMode': 'cookie', 'authMode': 'cookie',
} }
auth_info = self._download_json( auth_info = self._gigya_login(auth_data)
'https://accounts.eu1.gigya.com/accounts.login', None,
note='Logging in', errnote='Unable to log in',
data=urlencode_postdata(auth_data))
error_message = auth_info.get('errorDetails') or auth_info.get('errorMessage')
if error_message:
raise ExtractorError(
'Unable to login: %s' % error_message, expected=True)
# Sometimes authentication fails for no good reason, retry # Sometimes authentication fails for no good reason, retry
login_attempt = 1 login_attempt = 1

View File

@ -0,0 +1,21 @@
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
ExtractorError,
urlencode_postdata,
)
class GigyaBaseIE(InfoExtractor):
def _gigya_login(self, auth_data):
auth_info = self._download_json(
'https://accounts.eu1.gigya.com/accounts.login', None,
note='Logging in', errnote='Unable to log in',
data=urlencode_postdata(auth_data))
error_message = auth_info.get('errorDetails') or auth_info.get('errorMessage')
if error_message:
raise ExtractorError(
'Unable to login: %s' % error_message, expected=True)
return auth_info

View File

@ -2,19 +2,18 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import GigyaBaseIE
from ..compat import compat_str from ..compat import compat_str
from ..utils import ( from ..utils import (
ExtractorError,
int_or_none, int_or_none,
parse_duration, parse_duration,
try_get, try_get,
unified_timestamp, unified_timestamp,
urlencode_postdata,
) )
class MedialaanIE(InfoExtractor): class MedialaanIE(GigyaBaseIE):
_VALID_URL = r'''(?x) _VALID_URL = r'''(?x)
https?:// https?://
(?:www\.|nieuws\.)? (?:www\.|nieuws\.)?
@ -119,15 +118,7 @@ class MedialaanIE(InfoExtractor):
'password': password, 'password': password,
} }
auth_info = self._download_json( auth_info = self._gigya_login(auth_data)
'https://accounts.eu1.gigya.com/accounts.login', None,
note='Logging in', errnote='Unable to log in',
data=urlencode_postdata(auth_data))
error_message = auth_info.get('errorDetails') or auth_info.get('errorMessage')
if error_message:
raise ExtractorError(
'Unable to login: %s' % error_message, expected=True)
self._uid = auth_info['UID'] self._uid = auth_info['UID']
self._uid_signature = auth_info['UIDSignature'] self._uid_signature = auth_info['UIDSignature']