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.

115 lines
3.8 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. float_or_none,
  7. int_or_none,
  8. unified_timestamp,
  9. url_or_none,
  10. )
  11. class DctpTvIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?dctp\.tv/(?:#/)?filme/(?P<id>[^/?#&]+)'
  13. _TESTS = [{
  14. # 4x3
  15. 'url': 'http://www.dctp.tv/filme/videoinstallation-fuer-eine-kaufhausfassade/',
  16. 'info_dict': {
  17. 'id': '95eaa4f33dad413aa17b4ee613cccc6c',
  18. 'display_id': 'videoinstallation-fuer-eine-kaufhausfassade',
  19. 'ext': 'flv',
  20. 'title': 'Videoinstallation für eine Kaufhausfassade',
  21. 'description': 'Kurzfilm',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'duration': 71.24,
  24. 'timestamp': 1302172322,
  25. 'upload_date': '20110407',
  26. },
  27. 'params': {
  28. # rtmp download
  29. 'skip_download': True,
  30. },
  31. }, {
  32. # 16x9
  33. 'url': 'http://www.dctp.tv/filme/sind-youtuber-die-besseren-lehrer/',
  34. 'only_matching': True,
  35. }]
  36. _BASE_URL = 'http://dctp-ivms2-restapi.s3.amazonaws.com'
  37. def _real_extract(self, url):
  38. display_id = self._match_id(url)
  39. version = self._download_json(
  40. '%s/version.json' % self._BASE_URL, display_id,
  41. 'Downloading version JSON')
  42. restapi_base = '%s/%s/restapi' % (
  43. self._BASE_URL, version['version_name'])
  44. info = self._download_json(
  45. '%s/slugs/%s.json' % (restapi_base, display_id), display_id,
  46. 'Downloading video info JSON')
  47. media = self._download_json(
  48. '%s/media/%s.json' % (restapi_base, compat_str(info['object_id'])),
  49. display_id, 'Downloading media JSON')
  50. uuid = media['uuid']
  51. title = media['title']
  52. ratio = '16x9' if media.get('is_wide') else '4x3'
  53. play_path = 'mp4:%s_dctp_0500_%s.m4v' % (uuid, ratio)
  54. servers = self._download_json(
  55. 'http://www.dctp.tv/streaming_servers/', display_id,
  56. note='Downloading server list JSON', fatal=False)
  57. if servers:
  58. endpoint = next(
  59. server['endpoint']
  60. for server in servers
  61. if url_or_none(server.get('endpoint')) and
  62. 'cloudfront' in server['endpoint'])
  63. else:
  64. endpoint = 'rtmpe://s2pqqn4u96e4j8.cloudfront.net/cfx/st/'
  65. app = self._search_regex(
  66. r'^rtmpe?://[^/]+/(?P<app>.*)$', endpoint, 'app')
  67. formats = [{
  68. 'url': endpoint,
  69. 'app': app,
  70. 'play_path': play_path,
  71. 'page_url': url,
  72. 'player_url': 'http://svm-prod-dctptv-static.s3.amazonaws.com/dctptv-relaunch2012-110.swf',
  73. 'ext': 'flv',
  74. }]
  75. thumbnails = []
  76. images = media.get('images')
  77. if isinstance(images, list):
  78. for image in images:
  79. if not isinstance(image, dict):
  80. continue
  81. image_url = url_or_none(image.get('url'))
  82. if not image_url:
  83. continue
  84. thumbnails.append({
  85. 'url': image_url,
  86. 'width': int_or_none(image.get('width')),
  87. 'height': int_or_none(image.get('height')),
  88. })
  89. return {
  90. 'id': uuid,
  91. 'display_id': display_id,
  92. 'title': title,
  93. 'alt_title': media.get('subtitle'),
  94. 'description': media.get('description') or media.get('teaser'),
  95. 'timestamp': unified_timestamp(media.get('created')),
  96. 'duration': float_or_none(media.get('duration_in_ms'), scale=1000),
  97. 'thumbnails': thumbnails,
  98. 'formats': formats,
  99. }