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.

93 lines
3.4 KiB

  1. from __future__ import unicode_literals
  2. from .canvas import CanvasIE
  3. from .common import InfoExtractor
  4. class KetnetIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?ketnet\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  6. _TESTS = [{
  7. 'url': 'https://www.ketnet.be/kijken/zomerse-filmpjes',
  8. 'md5': '6bdeb65998930251bbd1c510750edba9',
  9. 'info_dict': {
  10. 'id': 'zomerse-filmpjes',
  11. 'ext': 'mp4',
  12. 'title': 'Gluur mee op de filmset en op Pennenzakkenrock',
  13. 'description': 'Gluur mee met Ghost Rockers op de filmset',
  14. 'thumbnail': r're:^https?://.*\.jpg$',
  15. }
  16. }, {
  17. # mzid in playerConfig instead of sources
  18. 'url': 'https://www.ketnet.be/kijken/nachtwacht/de-greystook',
  19. 'md5': '90139b746a0a9bd7bb631283f6e2a64e',
  20. 'info_dict': {
  21. 'id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
  22. 'display_id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
  23. 'ext': 'flv',
  24. 'title': 'Nachtwacht: De Greystook',
  25. 'description': 'md5:1db3f5dc4c7109c821261e7512975be7',
  26. 'thumbnail': r're:^https?://.*\.jpg$',
  27. 'duration': 1468.03,
  28. },
  29. 'expected_warnings': ['is not a supported codec', 'Unknown MIME type'],
  30. }, {
  31. 'url': 'https://www.ketnet.be/kijken/karrewiet/uitzending-8-september-2016',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'https://www.ketnet.be/achter-de-schermen/sien-repeteert-voor-stars-for-life',
  35. 'only_matching': True,
  36. }, {
  37. # mzsource, geo restricted to Belgium
  38. 'url': 'https://www.ketnet.be/kijken/nachtwacht/de-bermadoe',
  39. 'only_matching': True,
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(url, video_id)
  44. config = self._parse_json(
  45. self._search_regex(
  46. r'(?s)playerConfig\s*=\s*({.+?})\s*;', webpage,
  47. 'player config'),
  48. video_id)
  49. mzid = config.get('mzid')
  50. if mzid:
  51. return self.url_result(
  52. 'https://mediazone.vrt.be/api/v1/ketnet/assets/%s' % mzid,
  53. CanvasIE.ie_key(), video_id=mzid)
  54. title = config['title']
  55. formats = []
  56. for source_key in ('', 'mz'):
  57. source = config.get('%ssource' % source_key)
  58. if not isinstance(source, dict):
  59. continue
  60. for format_id, format_url in source.items():
  61. if format_id == 'hls':
  62. formats.extend(self._extract_m3u8_formats(
  63. format_url, video_id, 'mp4',
  64. entry_protocol='m3u8_native', m3u8_id=format_id,
  65. fatal=False))
  66. elif format_id == 'hds':
  67. formats.extend(self._extract_f4m_formats(
  68. format_url, video_id, f4m_id=format_id, fatal=False))
  69. else:
  70. formats.append({
  71. 'url': format_url,
  72. 'format_id': format_id,
  73. })
  74. self._sort_formats(formats)
  75. return {
  76. 'id': video_id,
  77. 'title': title,
  78. 'description': config.get('description'),
  79. 'thumbnail': config.get('image'),
  80. 'series': config.get('program'),
  81. 'episode': config.get('episode'),
  82. 'formats': formats,
  83. }