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.

114 lines
4.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_parse_urlparse
  5. from ..utils import (
  6. determine_ext,
  7. float_or_none,
  8. )
  9. class SpiegeltvIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?spiegel\.tv/(?:#/)?filme/(?P<id>[\-a-z0-9]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.spiegel.tv/filme/flug-mh370/',
  13. 'info_dict': {
  14. 'id': 'flug-mh370',
  15. 'ext': 'm4v',
  16. 'title': 'Flug MH370',
  17. 'description': 'Das Rätsel um die Boeing 777 der Malaysia-Airlines',
  18. 'thumbnail': 're:http://.*\.jpg$',
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. }
  24. }, {
  25. 'url': 'http://www.spiegel.tv/#/filme/alleskino-die-wahrheit-ueber-maenner/',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. if '/#/' in url:
  30. url = url.replace('/#/', '/')
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. title = self._html_search_regex(r'<h1.*?>(.*?)</h1>', webpage, 'title')
  34. apihost = 'http://spiegeltv-ivms2-restapi.s3.amazonaws.com'
  35. version_json = self._download_json(
  36. '%s/version.json' % apihost, video_id,
  37. note='Downloading version information')
  38. version_name = version_json['version_name']
  39. slug_json = self._download_json(
  40. '%s/%s/restapi/slugs/%s.json' % (apihost, version_name, video_id),
  41. video_id,
  42. note='Downloading object information')
  43. oid = slug_json['object_id']
  44. media_json = self._download_json(
  45. '%s/%s/restapi/media/%s.json' % (apihost, version_name, oid),
  46. video_id, note='Downloading media information')
  47. uuid = media_json['uuid']
  48. is_wide = media_json['is_wide']
  49. server_json = self._download_json(
  50. 'http://spiegeltv-prod-static.s3.amazonaws.com/projectConfigs/projectConfig.json',
  51. video_id, note='Downloading server information')
  52. format = '16x9' if is_wide else '4x3'
  53. formats = []
  54. for streamingserver in server_json['streamingserver']:
  55. endpoint = streamingserver.get('endpoint')
  56. if not endpoint:
  57. continue
  58. play_path = 'mp4:%s_spiegeltv_0500_%s.m4v' % (uuid, format)
  59. if endpoint.startswith('rtmp'):
  60. formats.append({
  61. 'url': endpoint,
  62. 'format_id': 'rtmp',
  63. 'app': compat_urllib_parse_urlparse(endpoint).path[1:],
  64. 'play_path': play_path,
  65. 'player_path': 'http://prod-static.spiegel.tv/frontend-076.swf',
  66. 'ext': 'flv',
  67. 'rtmp_live': True,
  68. })
  69. elif determine_ext(endpoint) == 'm3u8':
  70. formats.append({
  71. 'url': endpoint.replace('[video]', play_path),
  72. 'ext': 'm4v',
  73. 'format_id': 'hls', # Prefer hls since it allows to workaround georestriction
  74. 'protocol': 'm3u8',
  75. 'preference': 1,
  76. 'http_headers': {
  77. 'Accept-Encoding': 'deflate', # gzip causes trouble on the server side
  78. },
  79. })
  80. else:
  81. formats.append({
  82. 'url': endpoint,
  83. })
  84. self._check_formats(formats, video_id)
  85. thumbnails = []
  86. for image in media_json['images']:
  87. thumbnails.append({
  88. 'url': image['url'],
  89. 'width': image['width'],
  90. 'height': image['height'],
  91. })
  92. description = media_json['subtitle']
  93. duration = float_or_none(media_json.get('duration_in_ms'), scale=1000)
  94. return {
  95. 'id': video_id,
  96. 'title': title,
  97. 'description': description,
  98. 'duration': duration,
  99. 'thumbnails': thumbnails,
  100. 'formats': formats,
  101. }