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.

65 lines
2.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. _TEST = {
  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. def _real_extract(self, url):
  20. display_id = self._match_id(url)
  21. webpage = self._download_webpage(url, display_id)
  22. title = self._search_regex(
  23. r'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>',
  24. webpage, 'title', default=None) or self._og_search_title(webpage)
  25. video_id = self._html_search_regex(
  26. r'data-video=(["\'])(?P<id>.+?)\1', webpage, 'video id', group='id')
  27. data = self._download_json(
  28. 'https://mediazone.vrt.be/api/v1/canvas/assets/%s' % video_id, display_id)
  29. formats = []
  30. for target in data['targetUrls']:
  31. format_url, format_type = target.get('url'), target.get('type')
  32. if not format_url or not format_type:
  33. continue
  34. if format_type == 'HLS':
  35. formats.extend(self._extract_m3u8_formats(
  36. format_url, display_id, entry_protocol='m3u8_native',
  37. ext='mp4', preference=0, fatal=False, m3u8_id=format_type))
  38. elif format_type == 'HDS':
  39. formats.extend(self._extract_f4m_formats(
  40. format_url, display_id, f4m_id=format_type, fatal=False))
  41. else:
  42. formats.append({
  43. 'format_id': format_type,
  44. 'url': format_url,
  45. })
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'display_id': display_id,
  50. 'title': title,
  51. 'description': self._og_search_description(webpage),
  52. 'formats': formats,
  53. 'duration': float_or_none(data.get('duration'), 1000),
  54. 'thumbnail': data.get('posterImageUrl'),
  55. }