]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/awaan.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / awaan.py
CommitLineData
8e2898ed 1import base64
9f4921bf 2
3af1fac7 3from .common import InfoExtractor
3fc088f8 4from ..compat import (
15707c7e 5 compat_urllib_parse_urlencode,
3fc088f8 6 compat_str,
7)
f94639fa 8from ..utils import (
e0ddbd02 9 format_field,
f94639fa
S
10 int_or_none,
11 parse_iso8601,
b477da20 12 smuggle_url,
13 unsmuggle_url,
6e6bc8da 14 urlencode_postdata,
f94639fa 15)
cd6b555e 16
3af1fac7 17
7367bdef 18class AWAANIE(InfoExtractor):
d3d8d818 19 _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<id>\d+)/(?P<season_id>\d+))?'
9f4921bf 20
21 def _real_extract(self, url):
5ad28e7f 22 show_id, video_id, season_id = self._match_valid_url(url).groups()
9f4921bf 23 if video_id and int(video_id) > 0:
6afe044b 24 return self.url_result(
7367bdef 25 'http://awaan.ae/media/%s' % video_id, 'AWAANVideo')
6afe044b 26 elif season_id and int(season_id) > 0:
27 return self.url_result(smuggle_url(
7367bdef
RA
28 'http://awaan.ae/program/season/%s' % season_id,
29 {'show_id': show_id}), 'AWAANSeason')
9f4921bf 30 else:
6afe044b 31 return self.url_result(
7367bdef 32 'http://awaan.ae/program/%s' % show_id, 'AWAANSeason')
9f4921bf 33
34
7367bdef
RA
35class AWAANBaseIE(InfoExtractor):
36 def _parse_video_data(self, video_data, video_id, is_live):
6afe044b 37 title = video_data.get('title_en') or video_data['title_ar']
38 img = video_data.get('img')
6afe044b 39
40 return {
41 'id': video_id,
39ca3b5c 42 'title': title,
7367bdef 43 'description': video_data.get('description_en') or video_data.get('description_ar'),
a70635b8 44 'thumbnail': format_field(img, None, 'http://admin.mangomolo.com/analytics/%s'),
7367bdef
RA
45 'duration': int_or_none(video_data.get('duration')),
46 'timestamp': parse_iso8601(video_data.get('create_time'), ' '),
6afe044b 47 'is_live': is_live,
2181983a 48 'uploader_id': video_data.get('user_id'),
6afe044b 49 }
50
6afe044b 51
7367bdef
RA
52class AWAANVideoIE(AWAANBaseIE):
53 IE_NAME = 'awaan:video'
8065d6c5
RA
54 _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?(?:video(?:/[^/]+)?|media|catchup/[^/]+/[^/]+)/(?P<id>\d+)'
55 _TESTS = [{
9f4921bf 56 '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',
7367bdef 57 'md5': '5f61c33bfc7794315c671a62d43116aa',
3af1fac7 58 'info_dict':
59 {
60 'id': '17375',
f94639fa 61 'ext': 'mp4',
3af1fac7 62 'title': 'رحلة العمر : الحلقة 1',
f94639fa 63 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6',
f94639fa
S
64 'duration': 2041,
65 'timestamp': 1227504126,
66 'upload_date': '20081124',
93933c98 67 'uploader_id': '71',
cd6b555e 68 },
8065d6c5
RA
69 }, {
70 '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',
71 'only_matching': True,
72 }]
3af1fac7 73
74 def _real_extract(self, url):
75 video_id = self._match_id(url)
f94639fa 76
7367bdef 77 video_data = self._download_json(
f94639fa 78 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id,
7367bdef
RA
79 video_id, headers={'Origin': 'http://awaan.ae'})
80 info = self._parse_video_data(video_data, video_id, False)
f94639fa 81
7d273a38
RA
82 embed_url = 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' + compat_urllib_parse_urlencode({
83 'id': video_data['id'],
84 'user_id': video_data['user_id'],
85 'signature': video_data['signature'],
86 'countries': 'Q0M=',
87 'filter': 'DENY',
88 })
89 info.update({
90 '_type': 'url_transparent',
91 'url': embed_url,
92 'ie_key': 'MangomoloVideo',
93 })
6afe044b 94 return info
f94639fa 95
f94639fa 96
7367bdef
RA
97class AWAANLiveIE(AWAANBaseIE):
98 IE_NAME = 'awaan:live'
8065d6c5 99 _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?live/(?P<id>\d+)'
7367bdef
RA
100 _TEST = {
101 'url': 'http://awaan.ae/live/6/dubai-tv',
102 'info_dict': {
103 'id': '6',
104 'ext': 'mp4',
105 'title': 're:Dubai Al Oula [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
106 'upload_date': '20150107',
107 'timestamp': 1420588800,
2181983a 108 'uploader_id': '71',
7367bdef
RA
109 },
110 'params': {
111 # m3u8 download
112 'skip_download': True,
113 },
114 }
8e2898ed 115
116 def _real_extract(self, url):
117 channel_id = self._match_id(url)
118
7367bdef 119 channel_data = self._download_json(
8e2898ed 120 'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id,
7367bdef
RA
121 channel_id, headers={'Origin': 'http://awaan.ae'})
122 info = self._parse_video_data(channel_data, channel_id, True)
8e2898ed 123
7d273a38
RA
124 embed_url = 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + compat_urllib_parse_urlencode({
125 'id': base64.b64encode(channel_data['user_id'].encode()).decode(),
126 'channelid': base64.b64encode(channel_data['id'].encode()).decode(),
127 'signature': channel_data['signature'],
128 'countries': 'Q0M=',
129 'filter': 'DENY',
130 })
131 info.update({
132 '_type': 'url_transparent',
133 'url': embed_url,
134 'ie_key': 'MangomoloLive',
135 })
6afe044b 136 return info
8e2898ed 137
138
7367bdef
RA
139class AWAANSeasonIE(InfoExtractor):
140 IE_NAME = 'awaan:season'
8065d6c5 141 _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))'
9f4921bf 142 _TEST = {
143 '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',
144 'info_dict':
145 {
b477da20 146 'id': '7910',
9f4921bf 147 'title': 'محاضرات الشيخ الشعراوي',
9f4921bf 148 },
149 'playlist_mincount': 27,
150 }
151
152 def _real_extract(self, url):
b477da20 153 url, smuggled_data = unsmuggle_url(url, {})
5ad28e7f 154 show_id, season_id = self._match_valid_url(url).groups()
48637515 155
9f4921bf 156 data = {}
157 if season_id:
9f4921bf 158 data['season'] = season_id
b477da20 159 show_id = smuggled_data.get('show_id')
160 if show_id is None:
7367bdef 161 season = self._download_json(
b477da20 162 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id,
7367bdef 163 season_id, headers={'Origin': 'http://awaan.ae'})
b477da20 164 show_id = season['id']
9f4921bf 165 data['show_id'] = show_id
7367bdef 166 show = self._download_json(
9f4921bf 167 'http://admin.mangomolo.com/analytics/index.php/plus/show',
7367bdef
RA
168 show_id, data=urlencode_postdata(data), headers={
169 'Origin': 'http://awaan.ae',
9f4921bf 170 'Content-Type': 'application/x-www-form-urlencoded'
f94639fa 171 })
50b9dd73 172 if not season_id:
173 season_id = show['default_season']
174 for season in show['seasons']:
175 if season['id'] == season_id:
176 title = season.get('title_en') or season['title_ar']
f94639fa 177
50b9dd73 178 entries = []
179 for video in show['videos']:
3fc088f8 180 video_id = compat_str(video['id'])
6afe044b 181 entries.append(self.url_result(
7367bdef 182 'http://awaan.ae/media/%s' % video_id, 'AWAANVideo', video_id))
f94639fa 183
50b9dd73 184 return self.playlist_result(entries, season_id, title)