]>
Commit | Line | Data |
---|---|---|
3be3c622 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
114ed20e | 4 | from .common import InfoExtractor |
c576ef1e | 5 | from ..compat import compat_urllib_parse |
02c126a7 | 6 | from ..utils import ( |
02c126a7 | 7 | ExtractorError, |
c576ef1e S |
8 | int_or_none, |
9 | parse_iso8601, | |
84c0ed50 | 10 | ) |
114ed20e | 11 | |
3be3c622 | 12 | |
114ed20e | 13 | class ShahidIE(InfoExtractor): |
14 | _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P<id>\d+)/?' | |
c576ef1e S |
15 | _TESTS = [{ |
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', | |
17 | 'info_dict': { | |
18 | 'id': '90574', | |
5de5ab89 | 19 | 'ext': 'mp4', |
c576ef1e S |
20 | 'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3', |
21 | 'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان', | |
22 | 'duration': 2972, | |
23 | 'timestamp': 1422057420, | |
24 | 'upload_date': '20150123', | |
114ed20e | 25 | }, |
c576ef1e S |
26 | 'params': { |
27 | # m3u8 download | |
28 | 'skip_download': True, | |
114ed20e | 29 | } |
c576ef1e S |
30 | }, { |
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', | |
33 | 'only_matching': True | |
34 | }] | |
114ed20e | 35 | |
c576ef1e S |
36 | def _handle_error(self, response): |
37 | if not isinstance(response, dict): | |
38 | return | |
39 | error = response.get('error') | |
40 | if error: | |
41 | raise ExtractorError( | |
42 | '%s returned error: %s' % (self.IE_NAME, '\n'.join(error.values())), | |
43 | expected=True) | |
44 | ||
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) | |
48 | return response | |
59e89e62 | 49 | |
114ed20e | 50 | def _real_extract(self, url): |
51 | video_id = self._match_id(url) | |
c576ef1e | 52 | |
114ed20e | 53 | webpage = self._download_webpage(url, video_id) |
3be3c622 | 54 | |
c576ef1e S |
55 | api_vars = { |
56 | 'id': video_id, | |
57 | 'type': 'player', | |
58 | 'url': 'http://api.shahid.net/api/v1_1', | |
59 | 'playerType': 'episode', | |
60 | } | |
61 | ||
62 | flashvars = self._search_regex( | |
63 | r'var\s+flashvars\s*=\s*({[^}]+})', webpage, 'flashvars', default=None) | |
64 | if flashvars: | |
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') | |
69 | if value: | |
70 | api_vars[key] = value | |
71 | ||
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') | |
a62fd1af | 75 | |
c576ef1e | 76 | formats = self._extract_m3u8_formats(player['url'], video_id, 'mp4') |
3be3c622 | 77 | |
c576ef1e S |
78 | video = self._download_json( |
79 | '%s/%s/%s?%s' % ( | |
80 | api_vars['url'], api_vars['playerType'], api_vars['id'], | |
81 | compat_urllib_parse.urlencode({ | |
82 | 'apiKey': 'sh@hid0nlin3', | |
83 | 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=', | |
1d67c966 | 84 | })), |
c576ef1e S |
85 | video_id, 'Downloading video JSON') |
86 | ||
87 | video = video[api_vars['playerType']] | |
88 | ||
89 | title = video['title'] | |
90 | description = video.get('description') | |
91 | thumbnail = video.get('thumbnailUrl') | |
92 | duration = int_or_none(video.get('duration')) | |
93 | timestamp = parse_iso8601(video.get('referenceDate')) | |
94 | categories = [ | |
95 | category['name'] | |
96 | for category in video.get('genres', []) if 'name' in category] | |
a62fd1af | 97 | |
114ed20e | 98 | return { |
99 | 'id': video_id, | |
100 | 'title': title, | |
114ed20e | 101 | 'description': description, |
c576ef1e | 102 | 'thumbnail': thumbnail, |
a62fd1af | 103 | 'duration': duration, |
c576ef1e S |
104 | 'timestamp': timestamp, |
105 | 'categories': categories, | |
114ed20e | 106 | 'formats': formats, |
107 | } |