mitele.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. 'episode': 'Programa 144',
  81. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  82. 'duration': 2913,
  83. },
  84. 'add_ie': ['Ooyala'],
  85. }, {
  86. # no explicit title
  87. 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/57b0de3dc915da14058b4876/player',
  88. 'info_dict': {
  89. 'id': '57b0de3dc915da14058b4876',
  90. 'ext': 'mp4',
  91. 'title': 'Cuarto Milenio Temporada 6 Programa 226',
  92. 'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
  93. 'series': 'Cuarto Milenio',
  94. 'season': 'Temporada 6',
  95. 'episode': 'Programa 226',
  96. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  97. 'duration': 7313,
  98. },
  99. 'params': {
  100. 'skip_download': True,
  101. },
  102. 'add_ie': ['Ooyala'],
  103. }, {
  104. 'url': 'http://www.mitele.es/series-online/la-que-se-avecina/57aac5c1c915da951a8b45ed/player',
  105. 'only_matching': True,
  106. }]
  107. def _real_extract(self, url):
  108. video_id = self._match_id(url)
  109. webpage = self._download_webpage(url, video_id)
  110. gigya_url = self._search_regex(r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s*src="([^"]*)">[^>]*</script>', webpage, 'gigya', default=None)
  111. gigya_sc = self._download_webpage(compat_urlparse.urljoin(r'http://www.mitele.es/', gigya_url), video_id, 'Downloading gigya script')
  112. # Get a appKey/uuid for getting the session key
  113. appKey_var = self._search_regex(r'value\("appGridApplicationKey",([0-9a-f]+)\)', gigya_sc, 'appKey variable')
  114. appKey = self._search_regex(r'var %s="([0-9a-f]+)"' % appKey_var, gigya_sc, 'appKey')
  115. uid = compat_str(uuid.uuid4())
  116. session_url = 'https://appgrid-api.cloud.accedo.tv/session?appKey=%s&uuid=%s' % (appKey, uid)
  117. session_json = self._download_json(session_url, video_id, 'Downloading session keys')
  118. sessionKey = compat_str(session_json['sessionKey'])
  119. paths_url = 'https://appgrid-api.cloud.accedo.tv/metadata/general_configuration,%20web_configuration?sessionKey=' + sessionKey
  120. paths = self._download_json(paths_url, video_id, 'Downloading paths JSON')
  121. ooyala_s = paths['general_configuration']['api_configuration']['ooyala_search']
  122. data_p = (
  123. 'http://' + ooyala_s['base_url'] + ooyala_s['full_path'] + ooyala_s['provider_id'] +
  124. '/docs/' + video_id + '?include_titles=Series,Season&product_name=test&format=full')
  125. data = self._download_json(data_p, video_id, 'Downloading data JSON')
  126. source = data['hits']['hits'][0]['_source']
  127. embedCode = source['offers'][0]['embed_codes'][0]
  128. titles = source['localizable_titles'][0]
  129. title = titles.get('title_medium') or titles['title_long']
  130. episode = titles['title_sort_name']
  131. description = titles['summary_long']
  132. titles_series = source['localizable_titles_series'][0]
  133. series = titles_series['title_long']
  134. titles_season = source['localizable_titles_season'][0]
  135. season = titles_season['title_medium']
  136. duration = parse_duration(source['videos'][0]['duration'])
  137. return {
  138. '_type': 'url_transparent',
  139. # for some reason only HLS is supported
  140. 'url': smuggle_url('ooyala:' + embedCode, {'supportedformats': 'm3u8'}),
  141. 'id': video_id,
  142. 'title': title,
  143. 'description': description,
  144. 'series': series,
  145. 'season': season,
  146. 'episode': episode,
  147. 'duration': duration,
  148. 'thumbnail': source['images'][0]['url'],
  149. }