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.

63 lines
1.9 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. _QUALITIES = [
  21. ('mobile', 'mobile'),
  22. ('web', 'SD'),
  23. ('url', 'MD'),
  24. ('high', 'HD'),
  25. ]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(
  29. 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
  30. data = self._parse_json(
  31. unescapeHTML(self._search_regex(
  32. r'data-media="([^"]+)"', webpage, 'data video')),
  33. video_id)
  34. if data.get('provider').lower() == 'youtube':
  35. video_url = data.get('downloadUrl') or data.get('url')
  36. return self.url_result(video_url, 'Youtube')
  37. formats = []
  38. for key, format_id in self._QUALITIES:
  39. format_url = data['sources'].get(key)
  40. if format_url:
  41. formats.append({
  42. 'format_id': format_id,
  43. 'url': format_url,
  44. })
  45. return {
  46. 'id': video_id,
  47. 'formats': formats,
  48. 'title': data['title'],
  49. 'description': data.get('description') or data.get('subtitle'),
  50. 'thumbnail': data.get('thumbnail'),
  51. 'duration': data.get('duration') or data.get('realDuration'),
  52. 'timestamp': int_or_none(data.get('created')),
  53. 'view_count': int_or_none(data.get('viewCount')),
  54. }