]>
Commit | Line | Data |
---|---|---|
cd6b555e | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
9f4921bf | 4 | import re |
8e2898ed | 5 | import base64 |
9f4921bf | 6 | |
3af1fac7 | 7 | from .common import InfoExtractor |
3fc088f8 | 8 | from ..compat import ( |
15707c7e | 9 | compat_urllib_parse_urlencode, |
3fc088f8 | 10 | compat_str, |
11 | ) | |
f94639fa S |
12 | from ..utils import ( |
13 | int_or_none, | |
14 | parse_iso8601, | |
5c2266df | 15 | sanitized_Request, |
b477da20 | 16 | smuggle_url, |
17 | unsmuggle_url, | |
6e6bc8da | 18 | urlencode_postdata, |
f94639fa | 19 | ) |
cd6b555e | 20 | |
3af1fac7 | 21 | |
f94639fa | 22 | class DCNIE(InfoExtractor): |
8065d6c5 | 23 | _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<video_id>\d+)/(?P<season_id>\d+))?' |
9f4921bf | 24 | |
25 | def _real_extract(self, url): | |
26 | show_id, video_id, season_id = re.match(self._VALID_URL, url).groups() | |
9f4921bf | 27 | if video_id and int(video_id) > 0: |
6afe044b | 28 | return self.url_result( |
29 | 'http://www.dcndigital.ae/media/%s' % video_id, 'DCNVideo') | |
30 | elif season_id and int(season_id) > 0: | |
31 | return self.url_result(smuggle_url( | |
32 | 'http://www.dcndigital.ae/program/season/%s' % season_id, | |
33 | {'show_id': show_id}), 'DCNSeason') | |
9f4921bf | 34 | else: |
6afe044b | 35 | return self.url_result( |
36 | 'http://www.dcndigital.ae/program/%s' % show_id, 'DCNSeason') | |
9f4921bf | 37 | |
38 | ||
6afe044b | 39 | class DCNBaseIE(InfoExtractor): |
40 | def _extract_video_info(self, video_data, video_id, is_live): | |
41 | title = video_data.get('title_en') or video_data['title_ar'] | |
42 | img = video_data.get('img') | |
43 | thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None | |
44 | duration = int_or_none(video_data.get('duration')) | |
45 | description = video_data.get('description_en') or video_data.get('description_ar') | |
46 | timestamp = parse_iso8601(video_data.get('create_time'), ' ') | |
47 | ||
48 | return { | |
49 | 'id': video_id, | |
50 | 'title': self._live_title(title) if is_live else title, | |
51 | 'description': description, | |
52 | 'thumbnail': thumbnail, | |
53 | 'duration': duration, | |
54 | 'timestamp': timestamp, | |
55 | 'is_live': is_live, | |
56 | } | |
57 | ||
8065d6c5 | 58 | def _extract_video_formats(self, webpage, video_id, m3u8_entry_protocol): |
bca9bea1 | 59 | formats = [] |
8065d6c5 RA |
60 | format_url_base = 'http' + self._html_search_regex( |
61 | [ | |
62 | r'file\s*:\s*"https?(://[^"]+)/playlist.m3u8', | |
63 | r'<a[^>]+href="rtsp(://[^"]+)"' | |
64 | ], webpage, 'format url') | |
65 | # TODO: Current DASH formats are broken - $Time$ pattern in | |
66 | # <SegmentTemplate> not implemented yet | |
67 | # formats.extend(self._extract_mpd_formats( | |
68 | # format_url_base + '/manifest.mpd', | |
69 | # video_id, mpd_id='dash', fatal=False)) | |
70 | formats.extend(self._extract_m3u8_formats( | |
71 | format_url_base + '/playlist.m3u8', video_id, 'mp4', | |
72 | m3u8_entry_protocol, m3u8_id='hls', fatal=False)) | |
73 | formats.extend(self._extract_f4m_formats( | |
74 | format_url_base + '/manifest.f4m', | |
75 | video_id, f4m_id='hds', fatal=False)) | |
6afe044b | 76 | self._sort_formats(formats) |
77 | return formats | |
78 | ||
79 | ||
80 | class DCNVideoIE(DCNBaseIE): | |
b477da20 | 81 | IE_NAME = 'dcn:video' |
8065d6c5 RA |
82 | _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?(?:video(?:/[^/]+)?|media|catchup/[^/]+/[^/]+)/(?P<id>\d+)' |
83 | _TESTS = [{ | |
9f4921bf | 84 | 'url': 'http://www.dcndigital.ae/#/video/%D8%B1%D8%AD%D9%84%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D8%B1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/17375', |
3af1fac7 | 85 | 'info_dict': |
86 | { | |
87 | 'id': '17375', | |
f94639fa | 88 | 'ext': 'mp4', |
3af1fac7 | 89 | 'title': 'رحلة العمر : الحلقة 1', |
f94639fa | 90 | 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6', |
f94639fa S |
91 | 'duration': 2041, |
92 | 'timestamp': 1227504126, | |
93 | 'upload_date': '20081124', | |
cd6b555e | 94 | }, |
95 | 'params': { | |
96 | # m3u8 download | |
97 | 'skip_download': True, | |
98 | }, | |
8065d6c5 RA |
99 | }, { |
100 | 'url': 'http://awaan.ae/video/26723981/%D8%AF%D8%A7%D8%B1-%D8%A7%D9%84%D8%B3%D9%84%D8%A7%D9%85:-%D8%AE%D9%8A%D8%B1-%D8%AF%D9%88%D8%B1-%D8%A7%D9%84%D8%A3%D9%86%D8%B5%D8%A7%D8%B1', | |
101 | 'only_matching': True, | |
102 | }] | |
3af1fac7 | 103 | |
104 | def _real_extract(self, url): | |
105 | video_id = self._match_id(url) | |
f94639fa | 106 | |
5c2266df | 107 | request = sanitized_Request( |
f94639fa S |
108 | 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id, |
109 | headers={'Origin': 'http://www.dcndigital.ae'}) | |
6afe044b | 110 | video_data = self._download_json(request, video_id) |
111 | info = self._extract_video_info(video_data, video_id, False) | |
f94639fa | 112 | |
3af1fac7 | 113 | webpage = self._download_webpage( |
9dd73ef4 | 114 | 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' + |
15707c7e | 115 | compat_urllib_parse_urlencode({ |
6afe044b | 116 | 'id': video_data['id'], |
117 | 'user_id': video_data['user_id'], | |
118 | 'signature': video_data['signature'], | |
f94639fa S |
119 | 'countries': 'Q0M=', |
120 | 'filter': 'DENY', | |
121 | }), video_id) | |
6afe044b | 122 | info['formats'] = self._extract_video_formats(webpage, video_id, 'm3u8_native') |
123 | return info | |
f94639fa | 124 | |
f94639fa | 125 | |
6afe044b | 126 | class DCNLiveIE(DCNBaseIE): |
8e2898ed | 127 | IE_NAME = 'dcn:live' |
8065d6c5 | 128 | _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?live/(?P<id>\d+)' |
8e2898ed | 129 | |
130 | def _real_extract(self, url): | |
131 | channel_id = self._match_id(url) | |
132 | ||
974c1b2d | 133 | request = sanitized_Request( |
8e2898ed | 134 | 'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id, |
135 | headers={'Origin': 'http://www.dcndigital.ae'}) | |
136 | ||
6afe044b | 137 | channel_data = self._download_json(request, channel_id) |
138 | info = self._extract_video_info(channel_data, channel_id, True) | |
8e2898ed | 139 | |
140 | webpage = self._download_webpage( | |
48637515 | 141 | 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + |
15707c7e | 142 | compat_urllib_parse_urlencode({ |
6afe044b | 143 | 'id': base64.b64encode(channel_data['user_id'].encode()).decode(), |
144 | 'channelid': base64.b64encode(channel_data['id'].encode()).decode(), | |
145 | 'signature': channel_data['signature'], | |
8e2898ed | 146 | 'countries': 'Q0M=', |
147 | 'filter': 'DENY', | |
148 | }), channel_id) | |
6afe044b | 149 | info['formats'] = self._extract_video_formats(webpage, channel_id, 'm3u8') |
150 | return info | |
8e2898ed | 151 | |
152 | ||
b477da20 | 153 | class DCNSeasonIE(InfoExtractor): |
154 | IE_NAME = 'dcn:season' | |
8065d6c5 | 155 | _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))' |
9f4921bf | 156 | _TEST = { |
157 | 'url': 'http://dcndigital.ae/#/program/205024/%D9%85%D8%AD%D8%A7%D8%B6%D8%B1%D8%A7%D8%AA-%D8%A7%D9%84%D8%B4%D9%8A%D8%AE-%D8%A7%D9%84%D8%B4%D8%B9%D8%B1%D8%A7%D9%88%D9%8A', | |
158 | 'info_dict': | |
159 | { | |
b477da20 | 160 | 'id': '7910', |
9f4921bf | 161 | 'title': 'محاضرات الشيخ الشعراوي', |
9f4921bf | 162 | }, |
163 | 'playlist_mincount': 27, | |
164 | } | |
165 | ||
166 | def _real_extract(self, url): | |
b477da20 | 167 | url, smuggled_data = unsmuggle_url(url, {}) |
9f4921bf | 168 | show_id, season_id = re.match(self._VALID_URL, url).groups() |
48637515 | 169 | |
9f4921bf | 170 | data = {} |
171 | if season_id: | |
9f4921bf | 172 | data['season'] = season_id |
b477da20 | 173 | show_id = smuggled_data.get('show_id') |
174 | if show_id is None: | |
974c1b2d | 175 | request = sanitized_Request( |
b477da20 | 176 | 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id, |
177 | headers={'Origin': 'http://www.dcndigital.ae'}) | |
178 | season = self._download_json(request, season_id) | |
179 | show_id = season['id'] | |
9f4921bf | 180 | data['show_id'] = show_id |
974c1b2d | 181 | request = sanitized_Request( |
9f4921bf | 182 | 'http://admin.mangomolo.com/analytics/index.php/plus/show', |
6e6bc8da | 183 | urlencode_postdata(data), |
9f4921bf | 184 | { |
185 | 'Origin': 'http://www.dcndigital.ae', | |
186 | 'Content-Type': 'application/x-www-form-urlencoded' | |
f94639fa S |
187 | }) |
188 | ||
9f4921bf | 189 | show = self._download_json(request, show_id) |
50b9dd73 | 190 | if not season_id: |
191 | season_id = show['default_season'] | |
192 | for season in show['seasons']: | |
193 | if season['id'] == season_id: | |
194 | title = season.get('title_en') or season['title_ar'] | |
f94639fa | 195 | |
50b9dd73 | 196 | entries = [] |
197 | for video in show['videos']: | |
3fc088f8 | 198 | video_id = compat_str(video['id']) |
6afe044b | 199 | entries.append(self.url_result( |
3fc088f8 | 200 | 'http://www.dcndigital.ae/media/%s' % video_id, 'DCNVideo', video_id)) |
f94639fa | 201 | |
50b9dd73 | 202 | return self.playlist_result(entries, season_id, title) |