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.

72 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. class KetnetIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?ketnet\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.ketnet.be/kijken/zomerse-filmpjes',
  7. 'md5': 'd907f7b1814ef0fa285c0475d9994ed7',
  8. 'info_dict': {
  9. 'id': 'zomerse-filmpjes',
  10. 'ext': 'mp4',
  11. 'title': 'Gluur mee op de filmset en op Pennenzakkenrock',
  12. 'description': 'Gluur mee met Ghost Rockers op de filmset',
  13. 'thumbnail': r're:^https?://.*\.jpg$',
  14. }
  15. }, {
  16. 'url': 'https://www.ketnet.be/kijken/karrewiet/uitzending-8-september-2016',
  17. 'only_matching': True,
  18. }, {
  19. 'url': 'https://www.ketnet.be/achter-de-schermen/sien-repeteert-voor-stars-for-life',
  20. 'only_matching': True,
  21. }, {
  22. # mzsource, geo restricted to Belgium
  23. 'url': 'https://www.ketnet.be/kijken/nachtwacht/de-bermadoe',
  24. 'only_matching': True,
  25. }]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. config = self._parse_json(
  30. self._search_regex(
  31. r'(?s)playerConfig\s*=\s*({.+?})\s*;', webpage,
  32. 'player config'),
  33. video_id)
  34. title = config['title']
  35. formats = []
  36. for source_key in ('', 'mz'):
  37. source = config.get('%ssource' % source_key)
  38. if not isinstance(source, dict):
  39. continue
  40. for format_id, format_url in source.items():
  41. if format_id == 'hls':
  42. formats.extend(self._extract_m3u8_formats(
  43. format_url, video_id, 'mp4',
  44. entry_protocol='m3u8_native', m3u8_id=format_id,
  45. fatal=False))
  46. elif format_id == 'hds':
  47. formats.extend(self._extract_f4m_formats(
  48. format_url, video_id, f4m_id=format_id, fatal=False))
  49. else:
  50. formats.append({
  51. 'url': format_url,
  52. 'format_id': format_id,
  53. })
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'description': config.get('description'),
  59. 'thumbnail': config.get('image'),
  60. 'series': config.get('program'),
  61. 'episode': config.get('episode'),
  62. 'formats': formats,
  63. }