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.

70 lines
2.3 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/[^?]+\?.*\bid=|ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=)(?P<id>\d+)'
  10. _TESTS = [{
  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. # geo restricted
  21. 'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'http://www.rtbf.be/ouftivi/niouzz?videoId=2055858',
  25. 'only_matching': True,
  26. }]
  27. _QUALITIES = [
  28. ('mobile', 'mobile'),
  29. ('web', 'SD'),
  30. ('url', 'MD'),
  31. ('high', 'HD'),
  32. ]
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(
  36. 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
  37. data = self._parse_json(
  38. unescapeHTML(self._search_regex(
  39. r'data-media="([^"]+)"', webpage, 'data video')),
  40. video_id)
  41. if data.get('provider').lower() == 'youtube':
  42. video_url = data.get('downloadUrl') or data.get('url')
  43. return self.url_result(video_url, 'Youtube')
  44. formats = []
  45. for key, format_id in self._QUALITIES:
  46. format_url = data['sources'].get(key)
  47. if format_url:
  48. formats.append({
  49. 'format_id': format_id,
  50. 'url': format_url,
  51. })
  52. return {
  53. 'id': video_id,
  54. 'formats': formats,
  55. 'title': data['title'],
  56. 'description': data.get('description') or data.get('subtitle'),
  57. 'thumbnail': data.get('thumbnail'),
  58. 'duration': data.get('duration') or data.get('realDuration'),
  59. 'timestamp': int_or_none(data.get('created')),
  60. 'view_count': int_or_none(data.get('viewCount')),
  61. }