2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
17 class PikselIE(InfoExtractor):
18 _VALID_URL = r'https?://player\.piksel\.com/v/(?P<id>[a-z0-9]+)'
20 'url': 'http://player.piksel.com/v/nv60p12f',
21 'md5': 'd9c17bbe9c3386344f9cfd32fad8d235',
25 'title': 'فن الحياة - الحلقة 1',
26 'description': 'احدث برامج الداعية الاسلامي " مصطفي حسني " فى رمضان 2016علي النهار نور',
27 'timestamp': 1465231790,
28 'upload_date': '20160606',
33 def _extract_url(webpage):
35 r'<iframe[^>]+src=["\'](?P<url>(?:https?:)?//player\.piksel\.com/v/[a-z0-9]+)',
38 return mobj.group('url')
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
42 webpage = self._download_webpage(url, video_id)
43 app_token = self._search_regex(
44 r'clientAPI\s*:\s*"([^"]+)"', webpage, 'app token')
45 response = self._download_json(
46 'http://player.piksel.com/ws/ws_program/api/%s/mode/json/apiv/5' % app_token,
50 failure = response.get('failure')
52 raise ExtractorError(response['failure']['reason'], expected=True)
53 video_data = response['WsProgramResponse']['program']['asset']
54 title = video_data['title']
58 m3u8_url = dict_get(video_data, [
65 formats.extend(self._extract_m3u8_formats(
66 m3u8_url, video_id, 'mp4', 'm3u8_native',
67 m3u8_id='hls', fatal=False))
69 asset_type = dict_get(video_data, ['assetType', 'asset_type'])
70 for asset_file in video_data.get('assetFiles', []):
71 # TODO: extract rtmp formats
72 http_url = asset_file.get('http_url')
76 vbr = int_or_none(asset_file.get('videoBitrate'), 1024)
77 abr = int_or_none(asset_file.get('audioBitrate'), 1024)
78 if asset_type == 'video':
80 elif asset_type == 'audio':
85 format_id.append(compat_str(tbr))
88 'format_id': '-'.join(format_id),
89 'url': unescapeHTML(http_url),
92 'width': int_or_none(asset_file.get('videoWidth')),
93 'height': int_or_none(asset_file.get('videoHeight')),
94 'filesize': int_or_none(asset_file.get('filesize')),
97 self._sort_formats(formats)
102 'description': video_data.get('description'),
103 'thumbnail': video_data.get('thumbnailUrl'),
104 'timestamp': parse_iso8601(video_data.get('dateadd')),