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.

119 lines
4.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import float_or_none
  5. class CanvasIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?(?P<site_id>canvas|een)\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
  9. 'md5': 'ea838375a547ac787d4064d8c7860a6c',
  10. 'info_dict': {
  11. 'id': 'mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e',
  12. 'display_id': 'de-afspraak-veilt-voor-de-warmste-week',
  13. 'ext': 'mp4',
  14. 'title': 'De afspraak veilt voor de Warmste Week',
  15. 'description': 'md5:24cb860c320dc2be7358e0e5aa317ba6',
  16. 'thumbnail': r're:^https?://.*\.jpg$',
  17. 'duration': 49.02,
  18. }
  19. }, {
  20. # with subtitles
  21. 'url': 'http://www.canvas.be/video/panorama/2016/pieter-0167',
  22. 'info_dict': {
  23. 'id': 'mz-ast-5240ff21-2d30-4101-bba6-92b5ec67c625',
  24. 'display_id': 'pieter-0167',
  25. 'ext': 'mp4',
  26. 'title': 'Pieter 0167',
  27. 'description': 'md5:943cd30f48a5d29ba02c3a104dc4ec4e',
  28. 'thumbnail': r're:^https?://.*\.jpg$',
  29. 'duration': 2553.08,
  30. 'subtitles': {
  31. 'nl': [{
  32. 'ext': 'vtt',
  33. }],
  34. },
  35. },
  36. 'params': {
  37. 'skip_download': True,
  38. }
  39. }, {
  40. 'url': 'https://www.een.be/sorry-voor-alles/herbekijk-sorry-voor-alles',
  41. 'info_dict': {
  42. 'id': 'mz-ast-11a587f8-b921-4266-82e2-0bce3e80d07f',
  43. 'display_id': 'herbekijk-sorry-voor-alles',
  44. 'ext': 'mp4',
  45. 'title': 'Herbekijk Sorry voor alles',
  46. 'description': 'md5:8bb2805df8164e5eb95d6a7a29dc0dd3',
  47. 'thumbnail': r're:^https?://.*\.jpg$',
  48. 'duration': 3788.06,
  49. },
  50. 'params': {
  51. 'skip_download': True,
  52. }
  53. }, {
  54. 'url': 'https://www.canvas.be/check-point/najaar-2016/de-politie-uw-vriend',
  55. 'only_matching': True,
  56. }]
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. site_id, display_id = mobj.group('site_id'), mobj.group('id')
  60. webpage = self._download_webpage(url, display_id)
  61. title = (self._search_regex(
  62. r'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>',
  63. webpage, 'title', default=None) or self._og_search_title(
  64. webpage)).strip()
  65. video_id = self._html_search_regex(
  66. r'data-video=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video id', group='id')
  67. data = self._download_json(
  68. 'https://mediazone.vrt.be/api/v1/%s/assets/%s'
  69. % (site_id, video_id), display_id)
  70. formats = []
  71. for target in data['targetUrls']:
  72. format_url, format_type = target.get('url'), target.get('type')
  73. if not format_url or not format_type:
  74. continue
  75. if format_type == 'HLS':
  76. formats.extend(self._extract_m3u8_formats(
  77. format_url, display_id, entry_protocol='m3u8_native',
  78. ext='mp4', preference=0, fatal=False, m3u8_id=format_type))
  79. elif format_type == 'HDS':
  80. formats.extend(self._extract_f4m_formats(
  81. format_url, display_id, f4m_id=format_type, fatal=False))
  82. elif format_type == 'MPEG_DASH':
  83. formats.extend(self._extract_mpd_formats(
  84. format_url, display_id, mpd_id=format_type, fatal=False))
  85. else:
  86. formats.append({
  87. 'format_id': format_type,
  88. 'url': format_url,
  89. })
  90. self._sort_formats(formats)
  91. subtitles = {}
  92. subtitle_urls = data.get('subtitleUrls')
  93. if isinstance(subtitle_urls, list):
  94. for subtitle in subtitle_urls:
  95. subtitle_url = subtitle.get('url')
  96. if subtitle_url and subtitle.get('type') == 'CLOSED':
  97. subtitles.setdefault('nl', []).append({'url': subtitle_url})
  98. return {
  99. 'id': video_id,
  100. 'display_id': display_id,
  101. 'title': title,
  102. 'description': self._og_search_description(webpage),
  103. 'formats': formats,
  104. 'duration': float_or_none(data.get('duration'), 1000),
  105. 'thumbnail': data.get('posterImageUrl'),
  106. 'subtitles': subtitles,
  107. }