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.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import uuid
  4. from .common import InfoExtractor
  5. from .ooyala import OoyalaIE
  6. from ..compat import (
  7. compat_str,
  8. compat_urllib_parse_urlencode,
  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. bas = location.get('bas')
  41. loc = location.get('loc')
  42. ogn = location.get('ogn')
  43. if None in (gat, bas, loc, ogn):
  44. continue
  45. token_data = {
  46. 'bas': bas,
  47. 'icd': loc,
  48. 'ogn': ogn,
  49. 'sta': '0',
  50. }
  51. media = self._download_json(
  52. '%s/?%s' % (gat, compat_urllib_parse_urlencode(token_data)),
  53. video_id, 'Downloading %s JSON' % location['loc'])
  54. file_ = media.get('file')
  55. if not file_:
  56. continue
  57. ext = determine_ext(file_)
  58. if ext == 'f4m':
  59. formats.extend(self._extract_f4m_formats(
  60. file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  61. video_id, f4m_id='hds', fatal=False))
  62. elif ext == 'm3u8':
  63. formats.extend(self._extract_m3u8_formats(
  64. file_, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  65. self._sort_formats(formats)
  66. return {
  67. 'id': video_id,
  68. 'formats': formats,
  69. 'thumbnail': player_data.get('data-poster') or config.get('poster', {}).get('imageUrl'),
  70. 'duration': duration,
  71. }
  72. class MiTeleIE(InfoExtractor):
  73. IE_DESC = 'mitele.es'
  74. _VALID_URL = r'https?://(?:www\.)?mitele\.es/(?:[^/]+/)+(?P<id>[^/]+)/player'
  75. _TESTS = [{
  76. 'url': 'http://www.mitele.es/programas-tv/diario-de/57b0dfb9c715da65618b4afa/player',
  77. 'info_dict': {
  78. 'id': '57b0dfb9c715da65618b4afa',
  79. 'ext': 'mp4',
  80. 'title': 'Tor, la web invisible',
  81. 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
  82. 'series': 'Diario de',
  83. 'season': 'La redacción',
  84. 'season_number': 14,
  85. 'season_id': 'diario_de_t14_11981',
  86. 'episode': 'Programa 144',
  87. 'episode_number': 3,
  88. 'thumbnail': r're:(?i)^https?://.*\.jpg$',
  89. 'duration': 2913,
  90. },
  91. 'add_ie': ['Ooyala'],
  92. }, {
  93. # no explicit title
  94. 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/57b0de3dc915da14058b4876/player',
  95. 'info_dict': {
  96. 'id': '57b0de3dc915da14058b4876',
  97. 'ext': 'mp4',
  98. 'title': 'Cuarto Milenio Temporada 6 Programa 226',
  99. 'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
  100. 'series': 'Cuarto Milenio',
  101. 'season': 'Temporada 6',
  102. 'season_number': 6,
  103. 'season_id': 'cuarto_milenio_t06_12715',
  104. 'episode': 'Programa 226',
  105. 'episode_number': 24,
  106. 'thumbnail': r're:(?i)^https?://.*\.jpg$',
  107. 'duration': 7313,
  108. },
  109. 'params': {
  110. 'skip_download': True,
  111. },
  112. 'add_ie': ['Ooyala'],
  113. }, {
  114. 'url': 'http://www.mitele.es/series-online/la-que-se-avecina/57aac5c1c915da951a8b45ed/player',
  115. 'only_matching': True,
  116. }]
  117. def _real_extract(self, url):
  118. video_id = self._match_id(url)
  119. webpage = self._download_webpage(url, video_id)
  120. gigya_url = self._search_regex(
  121. r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s+src="([^"]*)">[^>]*</script>',
  122. webpage, 'gigya', default=None)
  123. gigya_sc = self._download_webpage(
  124. compat_urlparse.urljoin('http://www.mitele.es/', gigya_url),
  125. video_id, 'Downloading gigya script')
  126. # Get a appKey/uuid for getting the session key
  127. appKey_var = self._search_regex(
  128. r'value\s*\(\s*["\']appGridApplicationKey["\']\s*,\s*([0-9a-f]+)',
  129. gigya_sc, 'appKey variable')
  130. appKey = self._search_regex(
  131. r'var\s+%s\s*=\s*["\']([0-9a-f]+)' % appKey_var, 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. }