dcn.py 8.0 KB

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