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.

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