You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
7.8 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  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_urlencode,
  8. compat_str,
  9. )
  10. from ..utils import (
  11. int_or_none,
  12. parse_iso8601,
  13. smuggle_url,
  14. unsmuggle_url,
  15. urlencode_postdata,
  16. )
  17. class AWAANIE(InfoExtractor):
  18. _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<video_id>\d+)/(?P<season_id>\d+))?'
  19. def _real_extract(self, url):
  20. show_id, video_id, season_id = re.match(self._VALID_URL, url).groups()
  21. if video_id and int(video_id) > 0:
  22. return self.url_result(
  23. 'http://awaan.ae/media/%s' % video_id, 'AWAANVideo')
  24. elif season_id and int(season_id) > 0:
  25. return self.url_result(smuggle_url(
  26. 'http://awaan.ae/program/season/%s' % season_id,
  27. {'show_id': show_id}), 'AWAANSeason')
  28. else:
  29. return self.url_result(
  30. 'http://awaan.ae/program/%s' % show_id, 'AWAANSeason')
  31. class AWAANBaseIE(InfoExtractor):
  32. def _parse_video_data(self, video_data, video_id, is_live):
  33. title = video_data.get('title_en') or video_data['title_ar']
  34. img = video_data.get('img')
  35. return {
  36. 'id': video_id,
  37. 'title': self._live_title(title) if is_live else title,
  38. 'description': video_data.get('description_en') or video_data.get('description_ar'),
  39. 'thumbnail': 'http://admin.mangomolo.com/analytics/%s' % img if img else None,
  40. 'duration': int_or_none(video_data.get('duration')),
  41. 'timestamp': parse_iso8601(video_data.get('create_time'), ' '),
  42. 'is_live': is_live,
  43. }
  44. def _extract_video_formats(self, webpage, video_id, m3u8_entry_protocol):
  45. formats = []
  46. format_url_base = 'http' + self._html_search_regex(
  47. [
  48. r'file\s*:\s*"https?(://[^"]+)/playlist.m3u8',
  49. r'<a[^>]+href="rtsp(://[^"]+)"'
  50. ], webpage, 'format url')
  51. formats.extend(self._extract_mpd_formats(
  52. format_url_base + '/manifest.mpd',
  53. video_id, mpd_id='dash', fatal=False))
  54. formats.extend(self._extract_m3u8_formats(
  55. format_url_base + '/playlist.m3u8', video_id, 'mp4',
  56. m3u8_entry_protocol, m3u8_id='hls', fatal=False))
  57. formats.extend(self._extract_f4m_formats(
  58. format_url_base + '/manifest.f4m',
  59. video_id, f4m_id='hds', fatal=False))
  60. self._sort_formats(formats)
  61. return formats
  62. class AWAANVideoIE(AWAANBaseIE):
  63. IE_NAME = 'awaan:video'
  64. _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?(?:video(?:/[^/]+)?|media|catchup/[^/]+/[^/]+)/(?P<id>\d+)'
  65. _TESTS = [{
  66. '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',
  67. 'md5': '5f61c33bfc7794315c671a62d43116aa',
  68. 'info_dict':
  69. {
  70. 'id': '17375',
  71. 'ext': 'mp4',
  72. 'title': 'رحلة العمر : الحلقة 1',
  73. 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6',
  74. 'duration': 2041,
  75. 'timestamp': 1227504126,
  76. 'upload_date': '20081124',
  77. },
  78. }, {
  79. 'url': 'http://awaan.ae/video/26723981/%D8%AF%D8%A7%D8%B1-%D8%A7%D9%84%D8%B3%D9%84%D8%A7%D9%85:-%D8%AE%D9%8A%D8%B1-%D8%AF%D9%88%D8%B1-%D8%A7%D9%84%D8%A3%D9%86%D8%B5%D8%A7%D8%B1',
  80. 'only_matching': True,
  81. }]
  82. def _real_extract(self, url):
  83. video_id = self._match_id(url)
  84. video_data = self._download_json(
  85. 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id,
  86. video_id, headers={'Origin': 'http://awaan.ae'})
  87. info = self._parse_video_data(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 AWAANLiveIE(AWAANBaseIE):
  100. IE_NAME = 'awaan:live'
  101. _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?live/(?P<id>\d+)'
  102. _TEST = {
  103. 'url': 'http://awaan.ae/live/6/dubai-tv',
  104. 'info_dict': {
  105. 'id': '6',
  106. 'ext': 'mp4',
  107. 'title': 're:Dubai Al Oula [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  108. 'upload_date': '20150107',
  109. 'timestamp': 1420588800,
  110. },
  111. 'params': {
  112. # m3u8 download
  113. 'skip_download': True,
  114. },
  115. }
  116. def _real_extract(self, url):
  117. channel_id = self._match_id(url)
  118. channel_data = self._download_json(
  119. 'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id,
  120. channel_id, headers={'Origin': 'http://awaan.ae'})
  121. info = self._parse_video_data(channel_data, channel_id, True)
  122. webpage = self._download_webpage(
  123. 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' +
  124. compat_urllib_parse_urlencode({
  125. 'id': base64.b64encode(channel_data['user_id'].encode()).decode(),
  126. 'channelid': base64.b64encode(channel_data['id'].encode()).decode(),
  127. 'signature': channel_data['signature'],
  128. 'countries': 'Q0M=',
  129. 'filter': 'DENY',
  130. }), channel_id)
  131. info['formats'] = self._extract_video_formats(webpage, channel_id, 'm3u8')
  132. return info
  133. class AWAANSeasonIE(InfoExtractor):
  134. IE_NAME = 'awaan:season'
  135. _VALID_URL = r'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))'
  136. _TEST = {
  137. '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',
  138. 'info_dict':
  139. {
  140. 'id': '7910',
  141. 'title': 'محاضرات الشيخ الشعراوي',
  142. },
  143. 'playlist_mincount': 27,
  144. }
  145. def _real_extract(self, url):
  146. url, smuggled_data = unsmuggle_url(url, {})
  147. show_id, season_id = re.match(self._VALID_URL, url).groups()
  148. data = {}
  149. if season_id:
  150. data['season'] = season_id
  151. show_id = smuggled_data.get('show_id')
  152. if show_id is None:
  153. season = self._download_json(
  154. 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id,
  155. season_id, headers={'Origin': 'http://awaan.ae'})
  156. show_id = season['id']
  157. data['show_id'] = show_id
  158. show = self._download_json(
  159. 'http://admin.mangomolo.com/analytics/index.php/plus/show',
  160. show_id, data=urlencode_postdata(data), headers={
  161. 'Origin': 'http://awaan.ae',
  162. 'Content-Type': 'application/x-www-form-urlencoded'
  163. })
  164. if not season_id:
  165. season_id = show['default_season']
  166. for season in show['seasons']:
  167. if season['id'] == season_id:
  168. title = season.get('title_en') or season['title_ar']
  169. entries = []
  170. for video in show['videos']:
  171. video_id = compat_str(video['id'])
  172. entries.append(self.url_result(
  173. 'http://awaan.ae/media/%s' % video_id, 'AWAANVideo', video_id))
  174. return self.playlist_result(entries, season_id, title)