+
+ try:
+ user_data = self._download_json(
+ 'https://shahid.mbc.net/wd/service/users/login',
+ None, 'Logging in', data=json.dumps({
+ 'email': email,
+ 'password': password,
+ 'basic': 'false',
+ }).encode('utf-8'), headers={
+ 'Content-Type': 'application/json; charset=UTF-8',
+ })['user']
+ except ExtractorError as e:
+ if isinstance(e.cause, compat_HTTPError):
+ self._handle_error(e)
+ raise
+
+ self._download_webpage(
+ 'https://shahid.mbc.net/populateContext',
+ None, 'Populate Context', data=urlencode_postdata({
+ 'firstName': user_data['firstName'],
+ 'lastName': user_data['lastName'],
+ 'userName': user_data['email'],
+ 'csg_user_name': user_data['email'],
+ 'subscriberId': user_data['id'],
+ 'sessionId': user_data['sessionId'],
+ }))
+
+ def _real_extract(self, url):
+ page_type, video_id = re.match(self._VALID_URL, url).groups()
+ if page_type == 'clip':
+ page_type = 'episode'
+
+ playout = self._call_api(
+ 'playout/url/' + video_id, video_id)['playout']
+
+ if playout.get('drm'):
+ raise ExtractorError('This video is DRM protected.', expected=True)
+
+ formats = self._extract_m3u8_formats(playout['url'], video_id, 'mp4')
+ self._sort_formats(formats)
+
+ # video = self._call_api(
+ # 'product/id', video_id, {
+ # 'id': video_id,
+ # 'productType': 'ASSET',
+ # 'productSubType': page_type.upper()
+ # })['productModel']
+
+ response = self._download_json(
+ 'http://api.shahid.net/api/v1_1/%s/%s' % (page_type, video_id),
+ video_id, 'Downloading video JSON', query={
+ 'apiKey': 'sh@hid0nlin3',
+ 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=',
+ })
+ data = response.get('data', {})
+ error = data.get('error')
+ if error:
+ raise ExtractorError(
+ '%s returned error: %s' % (self.IE_NAME, '\n'.join(error.values())),
+ expected=True)
+
+ video = data[page_type]
+ title = video['title']
+ categories = [
+ category['name']
+ for category in video.get('genres', []) if 'name' in category]
+