dcn.py 7.7 KB

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