dcn.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse,
  7. compat_urllib_request,
  8. )
  9. from ..utils import (
  10. int_or_none,
  11. parse_iso8601,
  12. smuggle_url,
  13. unsmuggle_url,
  14. )
  15. class DCNGeneralIE(InfoExtractor):
  16. _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<video_id>\d+)/(?P<season_id>\d+))?'
  17. def _real_extract(self, url):
  18. show_id, video_id, season_id = re.match(self._VALID_URL, url).groups()
  19. url = ''
  20. ie_key = ''
  21. if video_id and int(video_id) > 0:
  22. url = 'http://www.dcndigital.ae/#/media/%s' % video_id
  23. ie_key = 'DCNVideo'
  24. else:
  25. ie_key = 'DCNSeason'
  26. if season_id and int(season_id) > 0:
  27. url = smuggle_url('http://www.dcndigital.ae/#/program/season/%s' % season_id, {'show_id': show_id})
  28. else:
  29. url = 'http://www.dcndigital.ae/#/program/%s' % show_id
  30. return {
  31. 'url': url,
  32. '_type': 'url',
  33. 'ie_key': ie_key
  34. }
  35. class DCNVideoIE(InfoExtractor):
  36. IE_NAME = 'dcn:video'
  37. _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media)/(?P<id>\d+)'
  38. _TEST = {
  39. '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',
  40. 'info_dict':
  41. {
  42. 'id': '17375',
  43. 'ext': 'mp4',
  44. 'title': 'رحلة العمر : الحلقة 1',
  45. 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6',
  46. 'thumbnail': 're:^https?://.*\.jpg$',
  47. 'duration': 2041,
  48. 'timestamp': 1227504126,
  49. 'upload_date': '20081124',
  50. },
  51. 'params': {
  52. # m3u8 download
  53. 'skip_download': True,
  54. },
  55. }
  56. def _real_extract(self, url):
  57. video_id = self._match_id(url)
  58. request = compat_urllib_request.Request(
  59. 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id,
  60. headers={'Origin': 'http://www.dcndigital.ae'})
  61. video = self._download_json(request, video_id)
  62. title = video.get('title_en') or video['title_ar']
  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. img = video.get('img')
  84. thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None
  85. duration = int_or_none(video.get('duration'))
  86. description = video.get('description_en') or video.get('description_ar')
  87. timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ')
  88. return {
  89. 'id': video_id,
  90. 'title': title,
  91. 'description': description,
  92. 'thumbnail': thumbnail,
  93. 'duration': duration,
  94. 'timestamp': timestamp,
  95. 'formats': formats,
  96. }
  97. class DCNSeasonIE(InfoExtractor):
  98. IE_NAME = 'dcn:season'
  99. _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))'
  100. _TEST = {
  101. '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',
  102. 'info_dict':
  103. {
  104. 'id': '7910',
  105. 'title': 'محاضرات الشيخ الشعراوي',
  106. 'description': '',
  107. },
  108. 'playlist_mincount': 27,
  109. }
  110. def _real_extract(self, url):
  111. url, smuggled_data = unsmuggle_url(url, {})
  112. show_id, season_id = re.match(self._VALID_URL, url).groups()
  113. data = {}
  114. if season_id:
  115. data['season'] = season_id
  116. show_id = smuggled_data.get('show_id')
  117. if show_id is None:
  118. request = compat_urllib_request.Request(
  119. 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id,
  120. headers={'Origin': 'http://www.dcndigital.ae'})
  121. season = self._download_json(request, season_id)
  122. show_id = season['id']
  123. data['show_id'] = show_id
  124. request = compat_urllib_request.Request(
  125. 'http://admin.mangomolo.com/analytics/index.php/plus/show',
  126. compat_urllib_parse.urlencode(data),
  127. {
  128. 'Origin': 'http://www.dcndigital.ae',
  129. 'Content-Type': 'application/x-www-form-urlencoded'
  130. })
  131. show = self._download_json(request, show_id)
  132. season_id = season_id or show['default_season']
  133. title = show['cat'].get('title_en') or show['cat']['title_ar']
  134. description = show['cat'].get('description_en') or show['cat'].get('description_ar')
  135. entries = []
  136. for video in show['videos']:
  137. entries.append({
  138. 'url': 'http://www.dcndigital.ae/#/media/%s' % video['id'],
  139. '_type': 'url',
  140. 'ie_key': 'DCNVideo',
  141. })
  142. return {
  143. 'id': season_id,
  144. 'title': title,
  145. 'description': description,
  146. 'entries': entries,
  147. '_type': 'playlist',
  148. }