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.

209 lines
7.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import uuid
  5. from .common import InfoExtractor
  6. from .ooyala import OoyalaIE
  7. from ..compat import (
  8. compat_str,
  9. compat_urlparse,
  10. )
  11. from ..utils import (
  12. int_or_none,
  13. extract_attributes,
  14. determine_ext,
  15. smuggle_url,
  16. parse_duration,
  17. )
  18. class MiTeleBaseIE(InfoExtractor):
  19. def _get_player_info(self, url, webpage):
  20. player_data = extract_attributes(self._search_regex(
  21. r'(?s)(<ms-video-player.+?</ms-video-player>)',
  22. webpage, 'ms video player'))
  23. video_id = player_data['data-media-id']
  24. if player_data.get('data-cms-id') == 'ooyala':
  25. return self.url_result(
  26. 'ooyala:%s' % video_id, ie=OoyalaIE.ie_key(), video_id=video_id)
  27. config_url = compat_urlparse.urljoin(url, player_data['data-config'])
  28. config = self._download_json(
  29. config_url, video_id, 'Downloading config JSON')
  30. mmc_url = config['services']['mmc']
  31. duration = None
  32. formats = []
  33. for m_url in (mmc_url, mmc_url.replace('/flash.json', '/html5.json')):
  34. mmc = self._download_json(
  35. m_url, video_id, 'Downloading mmc JSON')
  36. if not duration:
  37. duration = int_or_none(mmc.get('duration'))
  38. for location in mmc['locations']:
  39. gat = self._proto_relative_url(location.get('gat'), 'http:')
  40. gcp = location.get('gcp')
  41. ogn = location.get('ogn')
  42. if None in (gat, gcp, ogn):
  43. continue
  44. token_data = {
  45. 'gcp': gcp,
  46. 'ogn': ogn,
  47. 'sta': 0,
  48. }
  49. media = self._download_json(
  50. gat, video_id, data=json.dumps(token_data).encode('utf-8'),
  51. headers={
  52. 'Content-Type': 'application/json;charset=utf-8',
  53. 'Referer': url,
  54. })
  55. stream = media.get('stream') or media.get('file')
  56. if not stream:
  57. continue
  58. ext = determine_ext(stream)
  59. if ext == 'f4m':
  60. formats.extend(self._extract_f4m_formats(
  61. stream + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  62. video_id, f4m_id='hds', fatal=False))
  63. elif ext == 'm3u8':
  64. formats.extend(self._extract_m3u8_formats(
  65. stream, video_id, 'mp4', 'm3u8_native',
  66. m3u8_id='hls', fatal=False))
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'formats': formats,
  71. 'thumbnail': player_data.get('data-poster') or config.get('poster', {}).get('imageUrl'),
  72. 'duration': duration,
  73. }
  74. class MiTeleIE(InfoExtractor):
  75. IE_DESC = 'mitele.es'
  76. _VALID_URL = r'https?://(?:www\.)?mitele\.es/(?:[^/]+/)+(?P<id>[^/]+)/player'
  77. _TESTS = [{
  78. 'url': 'http://www.mitele.es/programas-tv/diario-de/57b0dfb9c715da65618b4afa/player',
  79. 'info_dict': {
  80. 'id': '57b0dfb9c715da65618b4afa',
  81. 'ext': 'mp4',
  82. 'title': 'Tor, la web invisible',
  83. 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
  84. 'series': 'Diario de',
  85. 'season': 'La redacción',
  86. 'season_number': 14,
  87. 'season_id': 'diario_de_t14_11981',
  88. 'episode': 'Programa 144',
  89. 'episode_number': 3,
  90. 'thumbnail': r're:(?i)^https?://.*\.jpg$',
  91. 'duration': 2913,
  92. },
  93. 'add_ie': ['Ooyala'],
  94. }, {
  95. # no explicit title
  96. 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/57b0de3dc915da14058b4876/player',
  97. 'info_dict': {
  98. 'id': '57b0de3dc915da14058b4876',
  99. 'ext': 'mp4',
  100. 'title': 'Cuarto Milenio Temporada 6 Programa 226',
  101. 'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
  102. 'series': 'Cuarto Milenio',
  103. 'season': 'Temporada 6',
  104. 'season_number': 6,
  105. 'season_id': 'cuarto_milenio_t06_12715',
  106. 'episode': 'Programa 226',
  107. 'episode_number': 24,
  108. 'thumbnail': r're:(?i)^https?://.*\.jpg$',
  109. 'duration': 7313,
  110. },
  111. 'params': {
  112. 'skip_download': True,
  113. },
  114. 'add_ie': ['Ooyala'],
  115. }, {
  116. 'url': 'http://www.mitele.es/series-online/la-que-se-avecina/57aac5c1c915da951a8b45ed/player',
  117. 'only_matching': True,
  118. }]
  119. def _real_extract(self, url):
  120. video_id = self._match_id(url)
  121. webpage = self._download_webpage(url, video_id)
  122. gigya_url = self._search_regex(
  123. r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s+src="([^"]*)">[^>]*</script>',
  124. webpage, 'gigya', default=None)
  125. gigya_sc = self._download_webpage(
  126. compat_urlparse.urljoin('http://www.mitele.es/', gigya_url),
  127. video_id, 'Downloading gigya script')
  128. # Get a appKey/uuid for getting the session key
  129. appKey = self._search_regex(
  130. r'constant\s*\(\s*["\']_appGridApplicationKey["\']\s*,\s*["\']([0-9a-f]+)',
  131. gigya_sc, 'appKey')
  132. session_json = self._download_json(
  133. 'https://appgrid-api.cloud.accedo.tv/session',
  134. video_id, 'Downloading session keys', query={
  135. 'appKey': appKey,
  136. 'uuid': compat_str(uuid.uuid4()),
  137. })
  138. paths = self._download_json(
  139. 'https://appgrid-api.cloud.accedo.tv/metadata/general_configuration,%20web_configuration',
  140. video_id, 'Downloading paths JSON',
  141. query={'sessionKey': compat_str(session_json['sessionKey'])})
  142. ooyala_s = paths['general_configuration']['api_configuration']['ooyala_search']
  143. source = self._download_json(
  144. 'http://%s%s%s/docs/%s' % (
  145. ooyala_s['base_url'], ooyala_s['full_path'],
  146. ooyala_s['provider_id'], video_id),
  147. video_id, 'Downloading data JSON', query={
  148. 'include_titles': 'Series,Season',
  149. 'product_name': 'test',
  150. 'format': 'full',
  151. })['hits']['hits'][0]['_source']
  152. embedCode = source['offers'][0]['embed_codes'][0]
  153. titles = source['localizable_titles'][0]
  154. title = titles.get('title_medium') or titles['title_long']
  155. description = titles.get('summary_long') or titles.get('summary_medium')
  156. def get(key1, key2):
  157. value1 = source.get(key1)
  158. if not value1 or not isinstance(value1, list):
  159. return
  160. if not isinstance(value1[0], dict):
  161. return
  162. return value1[0].get(key2)
  163. series = get('localizable_titles_series', 'title_medium')
  164. season = get('localizable_titles_season', 'title_medium')
  165. season_number = int_or_none(source.get('season_number'))
  166. season_id = source.get('season_id')
  167. episode = titles.get('title_sort_name')
  168. episode_number = int_or_none(source.get('episode_number'))
  169. duration = parse_duration(get('videos', 'duration'))
  170. return {
  171. '_type': 'url_transparent',
  172. # for some reason only HLS is supported
  173. 'url': smuggle_url('ooyala:' + embedCode, {'supportedformats': 'm3u8,dash'}),
  174. 'id': video_id,
  175. 'title': title,
  176. 'description': description,
  177. 'series': series,
  178. 'season': season,
  179. 'season_number': season_number,
  180. 'season_id': season_id,
  181. 'episode': episode,
  182. 'episode_number': episode_number,
  183. 'duration': duration,
  184. 'thumbnail': get('images', 'url'),
  185. }