ketnet.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from .canvas import CanvasIE
  2. from .common import InfoExtractor
  3. from ..compat import compat_urllib_parse_unquote
  4. from ..utils import (
  5. int_or_none,
  6. parse_iso8601,
  7. )
  8. class KetnetIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?ketnet\.be/(?P<id>(?:[^/]+/)*[^/?#&]+)'
  10. _TESTS = [{
  11. 'url': 'https://www.ketnet.be/kijken/n/nachtwacht/3/nachtwacht-s3a1-de-greystook',
  12. 'md5': '37b2b7bb9b3dcaa05b67058dc3a714a9',
  13. 'info_dict': {
  14. 'id': 'pbs-pub-aef8b526-115e-4006-aa24-e59ff6c6ef6f$vid-ddb815bf-c8e7-467b-8879-6bad7a32cebd',
  15. 'ext': 'mp4',
  16. 'title': 'Nachtwacht - Reeks 3: Aflevering 1',
  17. 'description': 'De Nachtwacht krijgt te maken met een parasiet',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'duration': 1468.02,
  20. 'timestamp': 1609225200,
  21. 'upload_date': '20201229',
  22. 'series': 'Nachtwacht',
  23. 'season': 'Reeks 3',
  24. 'episode': 'De Greystook',
  25. 'episode_number': 1,
  26. },
  27. 'expected_warnings': ['is not a supported codec', 'Unknown MIME type'],
  28. }, {
  29. 'url': 'https://www.ketnet.be/themas/karrewiet/jaaroverzicht-20200/karrewiet-het-jaar-van-black-mamba',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. display_id = self._match_id(url)
  34. video = self._download_json(
  35. 'https://senior-bff.ketnet.be/graphql', display_id, query={
  36. 'query': '''{
  37. video(id: "content/ketnet/nl/%s.model.json") {
  38. description
  39. episodeNr
  40. imageUrl
  41. mediaReference
  42. programTitle
  43. publicationDate
  44. seasonTitle
  45. subtitleVideodetail
  46. titleVideodetail
  47. }
  48. }''' % display_id,
  49. })['data']['video']
  50. mz_id = compat_urllib_parse_unquote(video['mediaReference'])
  51. return {
  52. '_type': 'url_transparent',
  53. 'id': mz_id,
  54. 'title': video['titleVideodetail'],
  55. 'url': 'https://mediazone.vrt.be/api/v1/ketnet/assets/' + mz_id,
  56. 'thumbnail': video.get('imageUrl'),
  57. 'description': video.get('description'),
  58. 'timestamp': parse_iso8601(video.get('publicationDate')),
  59. 'series': video.get('programTitle'),
  60. 'season': video.get('seasonTitle'),
  61. 'episode': video.get('subtitleVideodetail'),
  62. 'episode_number': int_or_none(video.get('episodeNr')),
  63. 'ie_key': CanvasIE.ie_key(),
  64. }