2 from __future__ import unicode_literals
4 from .common import InfoExtractor
12 class ShahidIE(InfoExtractor):
13 _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': 'الفيلم الوثائقي - الملك عبد الله الإنسان',
26 'skip_download': True,
30 # shahid plus subscriber only
31 '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',
38 'url': 'http://api.shahid.net/api/v1_1',
39 'playerType': 'episode',
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44 webpage = self._download_webpage(url, video_id)
47 flash_vars = self._search_regex('var flashvars = ({[^}]+})', webpage, 'flashvars', None)
48 if flash_vars is not None:
49 for line in flash_vars.splitlines():
50 if '+' not in line and '(' not in line and ')' not in line:
52 player_info = self._parse_json(player_info, video_id, js_to_json, False)
53 if player_info is not None:
54 for key in self._api_vars:
55 if key in player_info:
56 self._api_vars[key] = player_info[key]
58 player_json_data = self._download_json(
59 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + self._api_vars['type'] + '.html',
62 if 'url' in player_json_data:
63 m3u8_url = player_json_data['url']
65 for error in player_json_data['error'].values():
66 raise ExtractorError(error)
67 formats = self._extract_m3u8_formats(m3u8_url, video_id)
69 video_info = self._download_json(
70 self._api_vars['url'] + '/' + self._api_vars['playerType'] + '/' + video_id + '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D',
73 if video_info.get('error'):
74 for error in video_info['error']:
75 raise ExtractorError(error)
76 video_info = video_info[self._api_vars['playerType']]
77 title = video_info['title']
78 thumbnail = video_info.get('thumbnailUrl')
79 categories = [category['name'] for category in video_info.get('genres')]
80 description = video_info.get('description')
81 duration = int_or_none(video_info.get('duration'))
86 'thumbnail': thumbnail,
87 'categories': categories,
88 'description': description,