rtbf.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import clean_html
  7. class RTBFVideoIE(InfoExtractor):
  8. _VALID_URL = r'https?://www.rtbf.be/video/(?P<title>[^?]+)\?.*id=(?P<id>[0-9]+)'
  9. _TEST = {
  10. 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274',
  11. 'md5': '799f334ddf2c0a582ba80c44655be570',
  12. 'info_dict': {
  13. 'id': '1921274',
  14. 'ext': 'mp4',
  15. 'title': 'Les Diables au coeur (épisode 2)',
  16. 'duration': 3099,
  17. }
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. video_id = mobj.group('id')
  22. # TODO more code goes here, for example ...
  23. webpage = self._download_webpage(url, video_id)
  24. title = self._html_search_regex(
  25. r'<meta property="og:description" content="([^"]*)"',
  26. webpage, 'title', mobj.group('title'))
  27. iframe_url = self._html_search_regex(r'<iframe [^>]*src="([^"]+)"',
  28. webpage, 'iframe')
  29. iframe = self._download_webpage(iframe_url, video_id)
  30. data_video_idx = iframe.find('data-video')
  31. next_data_idx = iframe.find('data-', data_video_idx + 1)
  32. json_data_start = data_video_idx + len('data-video=') + 1
  33. json_data_end = next_data_idx - 2
  34. video_data = json.loads(clean_html(iframe[json_data_start:json_data_end]))
  35. return {
  36. 'id': video_id,
  37. 'title': title,
  38. 'url': video_data['data']['downloadUrl'],
  39. 'duration': video_data['data']['duration'],
  40. }