cognito and vier coding guidelines update

This commit is contained in:
wernerkarlheisenberg 2018-01-24 21:26:03 +01:00
parent efc2dbd3a5
commit 1430955192
2 changed files with 17 additions and 19 deletions

View File

@ -1,14 +1,13 @@
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ExtractorError from ..utils import ExtractorError
class CognitoBaseIE(InfoExtractor):
class CognitoBaseIE(InfoExtractor):
def _cognito_login(self, auth_data): def _cognito_login(self, auth_data):
try: try:
import boto3 import boto3
from warrant import Cognito
from warrant.aws_srp import AWSSRP from warrant.aws_srp import AWSSRP
except ImportError: except ImportError:
raise ExtractorError('%s depends on boto3 and warrant.' % self.IE_NAME) raise ExtractorError('%s depends on boto3 and warrant.' % self.IE_NAME)
@ -16,15 +15,15 @@ class CognitoBaseIE(InfoExtractor):
region = auth_data['PoolId'].split('_')[0] region = auth_data['PoolId'].split('_')[0]
client = boto3.client( client = boto3.client(
'cognito-idp', 'cognito-idp',
region_name = region, region_name=region,
aws_access_key_id = 'SomeNonsenseValue', aws_access_key_id='SomeNonsenseValue',
aws_secret_access_key = 'YetAnotherNonsenseValue' aws_secret_access_key='YetAnotherNonsenseValue'
) )
aws = AWSSRP( aws = AWSSRP(
username = auth_data['Username'], username=auth_data['Username'],
password = auth_data['Password'], password=auth_data['Password'],
pool_id = auth_data['PoolId'], pool_id=auth_data['PoolId'],
client_id = auth_data['ClientId'], client_id=auth_data['ClientId'],
client=client client=client
) )
return aws.authenticate_user() return aws.authenticate_user()

View File

@ -13,6 +13,7 @@ from ..utils import (
from .cognito import CognitoBaseIE from .cognito import CognitoBaseIE
class VierVijfKijkOnlineIE(CognitoBaseIE): class VierVijfKijkOnlineIE(CognitoBaseIE):
IE_NAME = 'viervijfkijkonline' IE_NAME = 'viervijfkijkonline'
IE_DESC = 'vier.be and vijf.be - Kijk Online' IE_DESC = 'vier.be and vijf.be - Kijk Online'
@ -24,7 +25,7 @@ class VierVijfKijkOnlineIE(CognitoBaseIE):
'ext': 'mp4', 'ext': 'mp4',
'title': 'Hotel Römantiek - Seizoen 1 - Aflevering 1', 'title': 'Hotel Römantiek - Seizoen 1 - Aflevering 1',
'series': 'Hotel Römantiek', 'series': 'Hotel Römantiek',
'season_number' : 1, 'season_number': 1,
'episode_number': 1, 'episode_number': 1,
}, },
'skip': 'This video is only available for registered users' 'skip': 'This video is only available for registered users'
@ -39,7 +40,6 @@ class VierVijfKijkOnlineIE(CognitoBaseIE):
_POOL_ID = 'eu-west-1_dViSsKM5Y' _POOL_ID = 'eu-west-1_dViSsKM5Y'
_CLIENT_ID = '6s1h851s8uplco5h6mqh1jac8m' _CLIENT_ID = '6s1h851s8uplco5h6mqh1jac8m'
def _real_initialize(self): def _real_initialize(self):
self._logged_in = False self._logged_in = False
self.id_token = '' self.id_token = ''
@ -51,8 +51,8 @@ class VierVijfKijkOnlineIE(CognitoBaseIE):
self.raise_login_required() self.raise_login_required()
auth_data = { auth_data = {
'PoolId' : self._POOL_ID, 'PoolId': self._POOL_ID,
'ClientId' : self._CLIENT_ID, 'ClientId': self._CLIENT_ID,
'Username': username, 'Username': username,
'Password': password, 'Password': password,
} }
@ -62,9 +62,6 @@ class VierVijfKijkOnlineIE(CognitoBaseIE):
self._logged_in = True self._logged_in = True
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
site = mobj.group('site')
if not self._logged_in: if not self._logged_in:
self._login() self._login()
@ -89,12 +86,12 @@ class VierVijfKijkOnlineIE(CognitoBaseIE):
api_url = 'https://api.viervijfzes.be/content/%s' % (video_id) api_url = 'https://api.viervijfzes.be/content/%s' % (video_id)
api_headers = { api_headers = {
'authorization' : self.id_token, 'authorization': self.id_token,
} }
api = self._download_json( api = self._download_json(
api_url, api_url,
None, note='Peforming API Call', errnote='API Call Failed', None, note='Peforming API Call', errnote='API Call Failed',
headers = api_headers, headers=api_headers,
) )
formats = [] formats = []
@ -106,11 +103,12 @@ class VierVijfKijkOnlineIE(CognitoBaseIE):
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'series': series, 'series': series,
'season_number' : int_or_none(season), 'season_number': int_or_none(season),
'episode_number': int_or_none(episode), 'episode_number': int_or_none(episode),
'formats': formats, 'formats': formats,
} }
class VierIE(InfoExtractor): class VierIE(InfoExtractor):
IE_NAME = 'vier' IE_NAME = 'vier'
IE_DESC = 'vier.be and vijf.be' IE_DESC = 'vier.be and vijf.be'
@ -295,6 +293,7 @@ class VierIE(InfoExtractor):
'formats': formats, 'formats': formats,
} }
class VierVideosIE(InfoExtractor): class VierVideosIE(InfoExtractor):
IE_NAME = 'vier:videos' IE_NAME = 'vier:videos'
_VALID_URL = r'https?://(?:www\.)?(?P<site>vier|vijf)\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)' _VALID_URL = r'https?://(?:www\.)?(?P<site>vier|vijf)\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'