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.

168 lines
6.3 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. strip_or_none,
  7. )
  8. class CanvasIE(InfoExtractor):
  9. _VALID_URL = r'https?://mediazone\.vrt\.be/api/v1/(?P<site_id>canvas|een|ketnet)/assets/(?P<id>m[dz]-ast-[^/?#&]+)'
  10. _TESTS = [{
  11. 'url': 'https://mediazone.vrt.be/api/v1/ketnet/assets/md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
  12. 'md5': '90139b746a0a9bd7bb631283f6e2a64e',
  13. 'info_dict': {
  14. 'id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
  15. 'display_id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
  16. 'ext': 'flv',
  17. 'title': 'Nachtwacht: De Greystook',
  18. 'description': 'md5:1db3f5dc4c7109c821261e7512975be7',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. 'duration': 1468.03,
  21. },
  22. 'expected_warnings': ['is not a supported codec', 'Unknown MIME type'],
  23. }, {
  24. 'url': 'https://mediazone.vrt.be/api/v1/canvas/assets/mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. site_id, video_id = mobj.group('site_id'), mobj.group('id')
  30. data = self._download_json(
  31. 'https://mediazone.vrt.be/api/v1/%s/assets/%s'
  32. % (site_id, video_id), video_id)
  33. title = data['title']
  34. description = data.get('description')
  35. formats = []
  36. for target in data['targetUrls']:
  37. format_url, format_type = target.get('url'), target.get('type')
  38. if not format_url or not format_type:
  39. continue
  40. if format_type == 'HLS':
  41. formats.extend(self._extract_m3u8_formats(
  42. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  43. m3u8_id=format_type, fatal=False))
  44. elif format_type == 'HDS':
  45. formats.extend(self._extract_f4m_formats(
  46. format_url, video_id, f4m_id=format_type, fatal=False))
  47. elif format_type == 'MPEG_DASH':
  48. formats.extend(self._extract_mpd_formats(
  49. format_url, video_id, mpd_id=format_type, fatal=False))
  50. elif format_type == 'HSS':
  51. formats.extend(self._extract_ism_formats(
  52. format_url, video_id, ism_id='mss', fatal=False))
  53. else:
  54. formats.append({
  55. 'format_id': format_type,
  56. 'url': format_url,
  57. })
  58. self._sort_formats(formats)
  59. subtitles = {}
  60. subtitle_urls = data.get('subtitleUrls')
  61. if isinstance(subtitle_urls, list):
  62. for subtitle in subtitle_urls:
  63. subtitle_url = subtitle.get('url')
  64. if subtitle_url and subtitle.get('type') == 'CLOSED':
  65. subtitles.setdefault('nl', []).append({'url': subtitle_url})
  66. return {
  67. 'id': video_id,
  68. 'display_id': video_id,
  69. 'title': title,
  70. 'description': description,
  71. 'formats': formats,
  72. 'duration': float_or_none(data.get('duration'), 1000),
  73. 'thumbnail': data.get('posterImageUrl'),
  74. 'subtitles': subtitles,
  75. }
  76. class CanvasEenIE(InfoExtractor):
  77. IE_DESC = 'canvas.be and een.be'
  78. _VALID_URL = r'https?://(?:www\.)?(?P<site_id>canvas|een)\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  79. _TESTS = [{
  80. 'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
  81. 'md5': 'ed66976748d12350b118455979cca293',
  82. 'info_dict': {
  83. 'id': 'mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e',
  84. 'display_id': 'de-afspraak-veilt-voor-de-warmste-week',
  85. 'ext': 'flv',
  86. 'title': 'De afspraak veilt voor de Warmste Week',
  87. 'description': 'md5:24cb860c320dc2be7358e0e5aa317ba6',
  88. 'thumbnail': r're:^https?://.*\.jpg$',
  89. 'duration': 49.02,
  90. },
  91. 'expected_warnings': ['is not a supported codec'],
  92. }, {
  93. # with subtitles
  94. 'url': 'http://www.canvas.be/video/panorama/2016/pieter-0167',
  95. 'info_dict': {
  96. 'id': 'mz-ast-5240ff21-2d30-4101-bba6-92b5ec67c625',
  97. 'display_id': 'pieter-0167',
  98. 'ext': 'mp4',
  99. 'title': 'Pieter 0167',
  100. 'description': 'md5:943cd30f48a5d29ba02c3a104dc4ec4e',
  101. 'thumbnail': r're:^https?://.*\.jpg$',
  102. 'duration': 2553.08,
  103. 'subtitles': {
  104. 'nl': [{
  105. 'ext': 'vtt',
  106. }],
  107. },
  108. },
  109. 'params': {
  110. 'skip_download': True,
  111. },
  112. 'skip': 'Pagina niet gevonden',
  113. }, {
  114. 'url': 'https://www.een.be/sorry-voor-alles/herbekijk-sorry-voor-alles',
  115. 'info_dict': {
  116. 'id': 'mz-ast-11a587f8-b921-4266-82e2-0bce3e80d07f',
  117. 'display_id': 'herbekijk-sorry-voor-alles',
  118. 'ext': 'mp4',
  119. 'title': 'Herbekijk Sorry voor alles',
  120. 'description': 'md5:8bb2805df8164e5eb95d6a7a29dc0dd3',
  121. 'thumbnail': r're:^https?://.*\.jpg$',
  122. 'duration': 3788.06,
  123. },
  124. 'params': {
  125. 'skip_download': True,
  126. },
  127. 'skip': 'Episode no longer available',
  128. }, {
  129. 'url': 'https://www.canvas.be/check-point/najaar-2016/de-politie-uw-vriend',
  130. 'only_matching': True,
  131. }]
  132. def _real_extract(self, url):
  133. mobj = re.match(self._VALID_URL, url)
  134. site_id, display_id = mobj.group('site_id'), mobj.group('id')
  135. webpage = self._download_webpage(url, display_id)
  136. title = strip_or_none(self._search_regex(
  137. r'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>',
  138. webpage, 'title', default=None) or self._og_search_title(
  139. webpage, default=None))
  140. video_id = self._html_search_regex(
  141. r'data-video=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video id',
  142. group='id')
  143. return {
  144. '_type': 'url_transparent',
  145. 'url': 'https://mediazone.vrt.be/api/v1/%s/assets/%s' % (site_id, video_id),
  146. 'ie_key': CanvasIE.ie_key(),
  147. 'id': video_id,
  148. 'display_id': display_id,
  149. 'title': title,
  150. 'description': self._og_search_description(webpage),
  151. }