dcn.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. )
  13. class DCNGeneralIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<video_id>\d+)/(?P<season_id>\d+))?'
  15. def _real_extract(self, url):
  16. show_id, video_id, season_id = re.match(self._VALID_URL, url).groups()
  17. url = ''
  18. ie_key = ''
  19. if video_id and int(video_id) > 0:
  20. url = 'http://www.dcndigital.ae/#/media/%s' % video_id
  21. ie_key = 'DCNVideo'
  22. else:
  23. ie_key = 'DCNShow'
  24. if season_id and int(season_id) > 0:
  25. url = 'http://www.dcndigital.ae/#/program/season/%s' % season_id
  26. else:
  27. url = 'http://www.dcndigital.ae/#/program/%s' % show_id
  28. return {
  29. 'url': url,
  30. '_type': 'url',
  31. 'ie_key': ie_key
  32. }
  33. class DCNVideoIE(InfoExtractor):
  34. _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media)/(?P<id>\d+)'
  35. _TEST = {
  36. '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',
  37. 'info_dict':
  38. {
  39. 'id': '17375',
  40. 'ext': 'mp4',
  41. 'title': 'رحلة العمر : الحلقة 1',
  42. 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6',
  43. 'thumbnail': 're:^https?://.*\.jpg$',
  44. 'duration': 2041,
  45. 'timestamp': 1227504126,
  46. 'upload_date': '20081124',
  47. },
  48. 'params': {
  49. # m3u8 download
  50. 'skip_download': True,
  51. },
  52. }
  53. def _real_extract(self, url):
  54. video_id = self._match_id(url)
  55. request = compat_urllib_request.Request(
  56. 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id,
  57. headers={'Origin': 'http://www.dcndigital.ae'})
  58. video = self._download_json(request, video_id)
  59. title = video.get('title_en') or video['title_ar']
  60. webpage = self._download_webpage(
  61. 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?'
  62. + compat_urllib_parse.urlencode({
  63. 'id': video['id'],
  64. 'user_id': video['user_id'],
  65. 'signature': video['signature'],
  66. 'countries': 'Q0M=',
  67. 'filter': 'DENY',
  68. }), video_id)
  69. m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url')
  70. formats = self._extract_m3u8_formats(
  71. m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
  72. rtsp_url = self._search_regex(
  73. r'<a[^>]+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False)
  74. if rtsp_url:
  75. formats.append({
  76. 'url': rtsp_url,
  77. 'format_id': 'rtsp',
  78. })
  79. self._sort_formats(formats)
  80. img = video.get('img')
  81. thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None
  82. duration = int_or_none(video.get('duration'))
  83. description = video.get('description_en') or video.get('description_ar')
  84. timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ')
  85. return {
  86. 'id': video_id,
  87. 'title': title,
  88. 'description': description,
  89. 'thumbnail': thumbnail,
  90. 'duration': duration,
  91. 'timestamp': timestamp,
  92. 'formats': formats,
  93. }
  94. class DCNShowIE(InfoExtractor):
  95. _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))'
  96. _TEST = {
  97. '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',
  98. 'info_dict':
  99. {
  100. 'id': '205024',
  101. 'title': 'محاضرات الشيخ الشعراوي',
  102. 'description': '',
  103. },
  104. 'playlist_mincount': 27,
  105. }
  106. def _real_extract(self, url):
  107. show_id, season_id = re.match(self._VALID_URL, url).groups()
  108. data = {}
  109. if season_id:
  110. request = compat_urllib_request.Request(
  111. 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id,
  112. headers={'Origin': 'http://www.dcndigital.ae'})
  113. season = self._download_json(request, season_id)
  114. show_id = season['id']
  115. data['season'] = season_id
  116. data['show_id'] = show_id
  117. request = compat_urllib_request.Request(
  118. 'http://admin.mangomolo.com/analytics/index.php/plus/show',
  119. compat_urllib_parse.urlencode(data),
  120. {
  121. 'Origin': 'http://www.dcndigital.ae',
  122. 'Content-Type': 'application/x-www-form-urlencoded'
  123. })
  124. show = self._download_json(request, show_id)
  125. title = show['cat'].get('title_en') or show['cat']['title_ar']
  126. description = show['cat'].get('description_en') or show['cat'].get('description_ar')
  127. entries = []
  128. for video in show['videos']:
  129. entries.append({
  130. 'url': 'http://www.dcndigital.ae/#/media/%s' % video['id'],
  131. '_type': 'url',
  132. 'ie_key': 'DCNVideo',
  133. })
  134. return {
  135. 'id': show_id,
  136. 'title': title,
  137. 'description': description,
  138. 'entries': entries,
  139. '_type': 'playlist',
  140. }