2 from __future__ import unicode_literals
7 from .common import InfoExtractor
8 from ..compat import compat_HTTPError
19 class ShahidIE(InfoExtractor):
20 _NETRC_MACHINE = 'shahid'
21 _VALID_URL = r'https?://shahid\.mbc\.net/ar/(?:serie|show|movie)s/[^/]+/(?P<type>episode|clip|movie)-(?P<id>\d+)'
23 'url': 'https://shahid.mbc.net/ar/shows/%D9%85%D8%AC%D9%84%D8%B3-%D8%A7%D9%84%D8%B4%D8%A8%D8%A7%D8%A8-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-1/clip-275286',
27 'title': 'مجلس الشباب الموسم 1 كليب 1',
28 'timestamp': 1506988800,
29 'upload_date': '20171003',
33 'skip_download': True,
36 'url': 'https://shahid.mbc.net/ar/movies/%D8%A7%D9%84%D9%82%D9%86%D8%A7%D8%B5%D8%A9/movie-151746',
39 # shahid plus subscriber only
40 'url': 'https://shahid.mbc.net/ar/series/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/episode-90511',
44 def _api2_request(self, *args, **kwargs):
46 return self._download_json(*args, **kwargs)
47 except ExtractorError as e:
48 if isinstance(e.cause, compat_HTTPError):
49 fail_data = self._parse_json(
50 e.cause.read().decode('utf-8'), None, fatal=False)
52 faults = fail_data.get('faults', [])
53 faults_message = ', '.join([clean_html(fault['userMessage']) for fault in faults if fault.get('userMessage')])
55 raise ExtractorError(faults_message, expected=True)
58 def _real_initialize(self):
59 email, password = self._get_login_info()
63 user_data = self._api2_request(
64 'https://shahid.mbc.net/wd/service/users/login',
65 None, 'Logging in', data=json.dumps({
69 }).encode('utf-8'), headers={
70 'Content-Type': 'application/json; charset=UTF-8',
73 self._download_webpage(
74 'https://shahid.mbc.net/populateContext',
75 None, 'Populate Context', data=urlencode_postdata({
76 'firstName': user_data['firstName'],
77 'lastName': user_data['lastName'],
78 'userName': user_data['email'],
79 'csg_user_name': user_data['email'],
80 'subscriberId': user_data['id'],
81 'sessionId': user_data['sessionId'],
84 def _get_api_data(self, response):
85 data = response.get('data', {})
87 error = data.get('error')
90 '%s returned error: %s' % (self.IE_NAME, '\n'.join(error.values())),
95 def _real_extract(self, url):
96 page_type, video_id = re.match(self._VALID_URL, url).groups()
97 if page_type == 'clip':
100 playout = self._api2_request(
101 'https://api2.shahid.net/proxy/v2/playout/url/' + video_id,
102 video_id, 'Downloading player JSON')['playout']
104 if playout.get('drm'):
105 raise ExtractorError('This video is DRM protected.', expected=True)
107 formats = self._extract_m3u8_formats(playout['url'], video_id, 'mp4')
108 self._sort_formats(formats)
110 video = self._get_api_data(self._download_json(
111 'http://api.shahid.net/api/v1_1/%s/%s' % (page_type, video_id),
112 video_id, 'Downloading video JSON', query={
113 'apiKey': 'sh@hid0nlin3',
114 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=',
117 title = video['title']
120 for category in video.get('genres', []) if 'name' in category]
125 'description': video.get('description'),
126 'thumbnail': video.get('thumbnailUrl'),
127 'duration': int_or_none(video.get('duration')),
128 'timestamp': parse_iso8601(video.get('referenceDate')),
129 'categories': categories,
130 'series': video.get('showTitle') or video.get('showName'),
131 'season': video.get('seasonTitle'),
132 'season_number': int_or_none(video.get('seasonNumber')),
133 'season_id': str_or_none(video.get('seasonId')),
134 'episode_number': int_or_none(video.get('number')),
135 'episode_id': video_id,