]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/dcn.py
correct season info extraction and simplify
[yt-dlp.git] / youtube_dl / extractor / dcn.py
CommitLineData
cd6b555e 1# coding: utf-8
2from __future__ import unicode_literals
3
9f4921bf 4import re
8e2898ed 5import base64
9f4921bf 6
3af1fac7 7from .common import InfoExtractor
f94639fa
S
8from ..compat import (
9 compat_urllib_parse,
10 compat_urllib_request,
11)
12from ..utils import (
13 int_or_none,
14 parse_iso8601,
b477da20 15 smuggle_url,
16 unsmuggle_url,
f94639fa 17)
cd6b555e 18
3af1fac7 19
9f4921bf 20class DCNGeneralIE(InfoExtractor):
21 _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<video_id>\d+)/(?P<season_id>\d+))?'
22
23 def _real_extract(self, url):
24 show_id, video_id, season_id = re.match(self._VALID_URL, url).groups()
25 url = ''
26 ie_key = ''
27 if video_id and int(video_id) > 0:
48637515 28 return self.url_result('http://www.dcndigital.ae/#/media/%s' % video_id, 'DCNVideo')
9f4921bf 29 else:
9f4921bf 30 if season_id and int(season_id) > 0:
b477da20 31 url = smuggle_url('http://www.dcndigital.ae/#/program/season/%s' % season_id, {'show_id': show_id})
9f4921bf 32 else:
33 url = 'http://www.dcndigital.ae/#/program/%s' % show_id
48637515 34 return self.url_result(url, 'DCNSeason')
9f4921bf 35
36
37class DCNVideoIE(InfoExtractor):
b477da20 38 IE_NAME = 'dcn:video'
8e2898ed 39 _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media|catchup/[^/]+/[^/]+)/(?P<id>\d+)'
3af1fac7 40 _TEST = {
9f4921bf 41 '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 42 'info_dict':
43 {
44 'id': '17375',
f94639fa 45 'ext': 'mp4',
3af1fac7 46 'title': 'رحلة العمر : الحلقة 1',
f94639fa
S
47 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6',
48 'thumbnail': 're:^https?://.*\.jpg$',
49 'duration': 2041,
50 'timestamp': 1227504126,
51 'upload_date': '20081124',
cd6b555e 52 },
53 'params': {
54 # m3u8 download
55 'skip_download': True,
56 },
3af1fac7 57 }
58
59 def _real_extract(self, url):
60 video_id = self._match_id(url)
f94639fa 61
cd6b555e 62 request = compat_urllib_request.Request(
f94639fa
S
63 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id,
64 headers={'Origin': 'http://www.dcndigital.ae'})
65
66 video = self._download_json(request, video_id)
67 title = video.get('title_en') or video['title_ar']
48637515 68 img = video.get('img')
69 thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None
70 duration = int_or_none(video.get('duration'))
71 description = video.get('description_en') or video.get('description_ar')
72 timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ')
f94639fa 73
3af1fac7 74 webpage = self._download_webpage(
f94639fa
S
75 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?'
76 + compat_urllib_parse.urlencode({
77 'id': video['id'],
78 'user_id': video['user_id'],
79 'signature': video['signature'],
80 'countries': 'Q0M=',
81 'filter': 'DENY',
82 }), video_id)
83
84 m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url')
85 formats = self._extract_m3u8_formats(
86 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
87
88 rtsp_url = self._search_regex(
89 r'<a[^>]+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False)
90 if rtsp_url:
91 formats.append({
92 'url': rtsp_url,
93 'format_id': 'rtsp',
94 })
95
96 self._sort_formats(formats)
97
3af1fac7 98 return {
99 'id': video_id,
100 'title': title,
f94639fa 101 'description': description,
3af1fac7 102 'thumbnail': thumbnail,
103 'duration': duration,
f94639fa 104 'timestamp': timestamp,
3af1fac7 105 'formats': formats,
106 }
9f4921bf 107
108
8e2898ed 109class DCNLiveIE(InfoExtractor):
110 IE_NAME = 'dcn:live'
111 _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?live/(?P<id>\d+)'
112 _TEST = {
113 'url': 'http://www.dcndigital.ae/#/live/6/dubai-tv',
114 'info_dict':
115 {
116 'id': '6',
117 'ext': 'mp4',
48637515 118 'title': 're:^Dubai Al Oula [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
119 'thumbnail': 're:^https?://.*\.png$',
120 'is_live': True,
8e2898ed 121 },
122 'params': {
123 # m3u8 download
124 'skip_download': True,
125 },
126 }
127
128 def _real_extract(self, url):
129 channel_id = self._match_id(url)
130
131 request = compat_urllib_request.Request(
132 'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id,
133 headers={'Origin': 'http://www.dcndigital.ae'})
134
135 channel = self._download_json(request, channel_id)
136 title = channel.get('title_en') or channel['title_ar']
48637515 137 img = channel.get('thumbnail')
138 thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None
139 description = channel.get('description_en') or channel.get('description_ar')
140 timestamp = parse_iso8601(channel.get('create_time') or channel.get('update_time'), ' ')
8e2898ed 141
142 webpage = self._download_webpage(
48637515 143 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' +
144 compat_urllib_parse.urlencode({
8e2898ed 145 'id': base64.b64encode(channel['user_id'].encode()).decode(),
146 'channelid': base64.b64encode(channel['id'].encode()).decode(),
147 'signature': channel['signature'],
148 'countries': 'Q0M=',
149 'filter': 'DENY',
150 }), channel_id)
151
152 m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url')
153 formats = self._extract_m3u8_formats(
154 m3u8_url, channel_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
155
156 rtsp_url = self._search_regex(
157 r'<a[^>]+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False)
158 if rtsp_url:
159 formats.append({
160 'url': rtsp_url,
161 'format_id': 'rtsp',
162 })
163
164 self._sort_formats(formats)
165
166 return {
167 'id': channel_id,
48637515 168 'title': self._live_title(title),
169 'description': description,
170 'thumbnail': thumbnail,
8e2898ed 171 'formats': formats,
172 'is_live': True,
173 }
174
175
b477da20 176class DCNSeasonIE(InfoExtractor):
177 IE_NAME = 'dcn:season'
9f4921bf 178 _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))'
179 _TEST = {
180 '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',
181 'info_dict':
182 {
b477da20 183 'id': '7910',
9f4921bf 184 'title': 'محاضرات الشيخ الشعراوي',
9f4921bf 185 },
186 'playlist_mincount': 27,
187 }
188
189 def _real_extract(self, url):
b477da20 190 url, smuggled_data = unsmuggle_url(url, {})
9f4921bf 191 show_id, season_id = re.match(self._VALID_URL, url).groups()
48637515 192
9f4921bf 193 data = {}
194 if season_id:
9f4921bf 195 data['season'] = season_id
b477da20 196 show_id = smuggled_data.get('show_id')
197 if show_id is None:
198 request = compat_urllib_request.Request(
199 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id,
200 headers={'Origin': 'http://www.dcndigital.ae'})
201 season = self._download_json(request, season_id)
202 show_id = season['id']
9f4921bf 203 data['show_id'] = show_id
204 request = compat_urllib_request.Request(
205 'http://admin.mangomolo.com/analytics/index.php/plus/show',
206 compat_urllib_parse.urlencode(data),
207 {
208 'Origin': 'http://www.dcndigital.ae',
209 'Content-Type': 'application/x-www-form-urlencoded'
210 })
48637515 211
9f4921bf 212 show = self._download_json(request, show_id)
b477da20 213 season_id = season_id or show['default_season']
48637515 214 season = {}
215 for _ in show['seasons']:
216 if _['id'] == season_id:
217 season = _
218 break
219 title = season.get('title_en') or season['title_ar']
220
9f4921bf 221 entries = []
222 for video in show['videos']:
48637515 223 entries.append(self.url_result('http://www.dcndigital.ae/#/media/%s' % video['id'], 'DCNVideo'))
224
225 return self.playlist_result(entries, season_id, title)