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.

94 lines
3.5 KiB

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