logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

dctp.py (3588B)


  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. 'md5': '3ffbd1556c3fe210724d7088fad723e3',
  17. 'info_dict': {
  18. 'id': '95eaa4f33dad413aa17b4ee613cccc6c',
  19. 'display_id': 'videoinstallation-fuer-eine-kaufhausfassade',
  20. 'ext': 'm4v',
  21. 'title': 'Videoinstallation für eine Kaufhausfassade',
  22. 'description': 'Kurzfilm',
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. 'duration': 71.24,
  25. 'timestamp': 1302172322,
  26. 'upload_date': '20110407',
  27. },
  28. }, {
  29. # 16x9
  30. 'url': 'http://www.dctp.tv/filme/sind-youtuber-die-besseren-lehrer/',
  31. 'only_matching': True,
  32. }]
  33. _BASE_URL = 'http://dctp-ivms2-restapi.s3.amazonaws.com'
  34. def _real_extract(self, url):
  35. display_id = self._match_id(url)
  36. version = self._download_json(
  37. '%s/version.json' % self._BASE_URL, display_id,
  38. 'Downloading version JSON')
  39. restapi_base = '%s/%s/restapi' % (
  40. self._BASE_URL, version['version_name'])
  41. info = self._download_json(
  42. '%s/slugs/%s.json' % (restapi_base, display_id), display_id,
  43. 'Downloading video info JSON')
  44. media = self._download_json(
  45. '%s/media/%s.json' % (restapi_base, compat_str(info['object_id'])),
  46. display_id, 'Downloading media JSON')
  47. uuid = media['uuid']
  48. title = media['title']
  49. is_wide = media.get('is_wide')
  50. formats = []
  51. def add_formats(suffix):
  52. templ = 'https://%%s/%s_dctp_%s.m4v' % (uuid, suffix)
  53. formats.extend([{
  54. 'format_id': 'hls-' + suffix,
  55. 'url': templ % 'cdn-segments.dctp.tv' + '/playlist.m3u8',
  56. 'protocol': 'm3u8_native',
  57. }, {
  58. 'format_id': 's3-' + suffix,
  59. 'url': templ % 'completed-media.s3.amazonaws.com',
  60. }, {
  61. 'format_id': 'http-' + suffix,
  62. 'url': templ % 'cdn-media.dctp.tv',
  63. }])
  64. add_formats('0500_' + ('16x9' if is_wide else '4x3'))
  65. if is_wide:
  66. add_formats('720p')
  67. thumbnails = []
  68. images = media.get('images')
  69. if isinstance(images, list):
  70. for image in images:
  71. if not isinstance(image, dict):
  72. continue
  73. image_url = url_or_none(image.get('url'))
  74. if not image_url:
  75. continue
  76. thumbnails.append({
  77. 'url': image_url,
  78. 'width': int_or_none(image.get('width')),
  79. 'height': int_or_none(image.get('height')),
  80. })
  81. return {
  82. 'id': uuid,
  83. 'display_id': display_id,
  84. 'title': title,
  85. 'alt_title': media.get('subtitle'),
  86. 'description': media.get('description') or media.get('teaser'),
  87. 'timestamp': unified_timestamp(media.get('created')),
  88. 'duration': float_or_none(media.get('duration_in_ms'), scale=1000),
  89. 'thumbnails': thumbnails,
  90. 'formats': formats,
  91. }