dcn.py 8.2 KB

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