rtbf.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. print title
  28. iframe_url = self._html_search_regex(r'<iframe [^>]*src="([^"]+)"',
  29. webpage, 'iframe')
  30. iframe = self._download_webpage(iframe_url, video_id)
  31. data_video_idx = iframe.find('data-video')
  32. next_data_idx = iframe.find('data-', data_video_idx + 1)
  33. json_data_start = data_video_idx + len('data-video=') + 1
  34. json_data_end = next_data_idx - 2
  35. video_data = json.loads(clean_html(iframe[json_data_start:json_data_end]))
  36. return {
  37. 'id': video_id,
  38. 'title': title,
  39. 'url': video_data['data']['downloadUrl'],
  40. 'duration': video_data['data']['duration'],
  41. }