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.

205 lines
7.6 KiB

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