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.

49 lines
1.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. unescapeHTML,
  7. )
  8. class RTBFIE(InfoExtractor):
  9. _VALID_URL = r'https?://www.rtbf.be/video/[^\?]+\?id=(?P<id>\d+)'
  10. _TEST = {
  11. 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274',
  12. 'md5': '799f334ddf2c0a582ba80c44655be570',
  13. 'info_dict': {
  14. 'id': '1921274',
  15. 'ext': 'mp4',
  16. 'title': 'Les Diables au coeur (épisode 2)',
  17. 'duration': 3099,
  18. }
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(
  23. 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
  24. data = self._parse_json(
  25. unescapeHTML(self._search_regex(
  26. r'data-video="([^"]+)"', webpage, 'data video')),
  27. video_id)
  28. video_url = data.get('downloadUrl') or data.get('url')
  29. if data.get('provider').lower() == 'youtube':
  30. return self.url_result(video_url, 'Youtube')
  31. return {
  32. 'id': video_id,
  33. 'url': video_url,
  34. 'title': data['title'],
  35. 'description': data.get('description') or data.get('subtitle'),
  36. 'thumbnail': data.get('thumbnail'),
  37. 'duration': data.get('duration') or data.get('realDuration'),
  38. 'timestamp': int_or_none(data.get('created')),
  39. 'view_count': int_or_none(data.get('viewCount')),
  40. }