spiegeltv.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import float_or_none
  5. class SpiegeltvIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?spiegel\.tv/(?:#/)?filme/(?P<id>[\-a-z0-9]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.spiegel.tv/filme/flug-mh370/',
  9. 'info_dict': {
  10. 'id': 'flug-mh370',
  11. 'ext': 'm4v',
  12. 'title': 'Flug MH370',
  13. 'description': 'Das Rätsel um die Boeing 777 der Malaysia-Airlines',
  14. 'thumbnail': 're:http://.*\.jpg$',
  15. },
  16. 'params': {
  17. # rtmp download
  18. 'skip_download': True,
  19. }
  20. }, {
  21. 'url': 'http://www.spiegel.tv/#/filme/alleskino-die-wahrheit-ueber-maenner/',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. if '/#/' in url:
  26. url = url.replace('/#/', '/')
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. title = self._html_search_regex(r'<h1.*?>(.*?)</h1>', webpage, 'title')
  30. apihost = 'http://spiegeltv-ivms2-restapi.s3.amazonaws.com'
  31. version_json = self._download_json(
  32. '%s/version.json' % apihost, video_id,
  33. note='Downloading version information')
  34. version_name = version_json['version_name']
  35. slug_json = self._download_json(
  36. '%s/%s/restapi/slugs/%s.json' % (apihost, version_name, video_id),
  37. video_id,
  38. note='Downloading object information')
  39. oid = slug_json['object_id']
  40. media_json = self._download_json(
  41. '%s/%s/restapi/media/%s.json' % (apihost, version_name, oid),
  42. video_id, note='Downloading media information')
  43. uuid = media_json['uuid']
  44. is_wide = media_json['is_wide']
  45. server_json = self._download_json(
  46. 'http://spiegeltv-prod-static.s3.amazonaws.com/projectConfigs/projectConfig.json',
  47. video_id, note='Downloading server information')
  48. server = server_json['streamingserver'][0]['endpoint']
  49. thumbnails = []
  50. for image in media_json['images']:
  51. thumbnails.append({
  52. 'url': image['url'],
  53. 'width': image['width'],
  54. 'height': image['height'],
  55. })
  56. description = media_json['subtitle']
  57. duration = float_or_none(media_json.get('duration_in_ms'), scale=1000)
  58. format = '16x9' if is_wide else '4x3'
  59. url = server + 'mp4:' + uuid + '_spiegeltv_0500_' + format + '.m4v'
  60. return {
  61. 'id': video_id,
  62. 'title': title,
  63. 'url': url,
  64. 'ext': 'm4v',
  65. 'description': description,
  66. 'duration': duration,
  67. 'thumbnails': thumbnails,
  68. 'rtmp_live': True,
  69. }