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