awaan.py 7.0 KB

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