2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
   5 from ..compat 
import compat_urllib_parse
 
  13 class ShahidIE(InfoExtractor
): 
  14     _VALID_URL 
= r
'https?://shahid\.mbc\.net/ar/episode/(?P<id>\d+)/?' 
  16         'url': 'https://shahid.mbc.net/ar/episode/90574/%D8%A7%D9%84%D9%85%D9%84%D9%83-%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D9%84%D9%87-%D8%A7%D9%84%D8%A5%D9%86%D8%B3%D8%A7%D9%86-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-3.html', 
  20             'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3', 
  21             'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان', 
  23             'timestamp': 1422057420, 
  24             'upload_date': '20150123', 
  28             'skip_download': True, 
  31         # shahid plus subscriber only 
  32         'url': 'https://shahid.mbc.net/ar/episode/90511/%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.html', 
  36     def _handle_error(self
, response
): 
  37         if not isinstance(response
, dict): 
  39         error 
= response
.get('error') 
  42                 '%s returned error: %s' % (self
.IE_NAME
, '\n'.join(error
.values())), 
  45     def _download_json(self
, url
, video_id
, note
='Downloading JSON metadata'): 
  46         response 
= super(ShahidIE
, self
)._download
_json
(url
, video_id
, note
)['data'] 
  47         self
._handle
_error
(response
) 
  50     def _real_extract(self
, url
): 
  51         video_id 
= self
._match
_id
(url
) 
  53         webpage 
= self
._download
_webpage
(url
, video_id
) 
  58             'url': 'http://api.shahid.net/api/v1_1', 
  59             'playerType': 'episode', 
  62         flashvars 
= self
._search
_regex
( 
  63             r
'var\s+flashvars\s*=\s*({[^}]+})', webpage
, 'flashvars', default
=None) 
  65             for key 
in api_vars
.keys(): 
  66                 value 
= self
._search
_regex
( 
  67                     r
'\b%s\s*:\s*(?P<q>["\'])(?P
<value
>.+?
)(?P
=q
)' % key, 
  68                     flashvars, 'type', default=None, group='value
') 
  72         player = self._download_json( 
  73             'https
://shahid
.mbc
.net
/arContent
/getPlayerContent
-param
-.id-%s.type-%s.html
' 
  74             % (video_id, api_vars['type']), video_id, 'Downloading player JSON
') 
  77             raise ExtractorError('This video 
is DRM protected
.', expected=True) 
  79         formats = self._extract_m3u8_formats(player['url
'], video_id, 'mp4
') 
  81         video = self._download_json( 
  83                 api_vars['url
'], api_vars['playerType
'], api_vars['id'], 
  84                 compat_urllib_parse.urlencode({ 
  85                     'apiKey
': 'sh
@hid0nlin3', 
  86                     'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex
+BpTK
/ooxy6vHaqs
=', 
  88             video_id, 'Downloading video JSON
') 
  90         video = video[api_vars['playerType
']] 
  92         title = video['title
'] 
  93         description = video.get('description
') 
  94         thumbnail = video.get('thumbnailUrl
') 
  95         duration = int_or_none(video.get('duration
')) 
  96         timestamp = parse_iso8601(video.get('referenceDate
')) 
  99             for category in video.get('genres
', []) if 'name
' in category] 
 104             'description
': description, 
 105             'thumbnail
': thumbnail, 
 106             'duration
': duration, 
 107             'timestamp
': timestamp, 
 108             'categories
': categories,