rtbf.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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'''(?x)
  10. https?://www\.rtbf\.be/
  11. (?:
  12. video/[^\?]+\?id=|
  13. ouftivi/heros/[^&]+&videoId=
  14. )
  15. (?P<id>\d+)
  16. '''
  17. _TESTS = [
  18. {
  19. 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274',
  20. 'md5': '799f334ddf2c0a582ba80c44655be570',
  21. 'info_dict': {
  22. 'id': '1921274',
  23. 'ext': 'mp4',
  24. 'title': 'Les Diables au coeur (épisode 2)',
  25. 'duration': 3099,
  26. }
  27. },
  28. {
  29. 'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442',
  30. 'md5': '25aea17e949e1e0c7c41270d60d25f22',
  31. 'info_dict': {
  32. 'id': '2057442',
  33. 'ext': 'mp4',
  34. 'title': 'Scooby-Doo, myst\xe8res associ\xe9s',
  35. 'duration': 1279,
  36. }
  37. },
  38. ]
  39. _QUALITIES = [
  40. ('mobile', 'mobile'),
  41. ('web', 'SD'),
  42. ('url', 'MD'),
  43. ('high', 'HD'),
  44. ]
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. webpage = self._download_webpage(
  48. 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
  49. data = self._parse_json(
  50. unescapeHTML(self._search_regex(
  51. r'data-media="([^"]+)"', webpage, 'data video')),
  52. video_id)
  53. if data.get('provider').lower() == 'youtube':
  54. video_url = data.get('downloadUrl') or data.get('url')
  55. return self.url_result(video_url, 'Youtube')
  56. formats = []
  57. for key, format_id in self._QUALITIES:
  58. format_url = data['sources'].get(key)
  59. if format_url:
  60. formats.append({
  61. 'format_id': format_id,
  62. 'url': format_url,
  63. })
  64. return {
  65. 'id': video_id,
  66. 'formats': formats,
  67. 'title': data['title'],
  68. 'description': data.get('description') or data.get('subtitle'),
  69. 'thumbnail': data.get('thumbnail'),
  70. 'duration': data.get('duration') or data.get('realDuration'),
  71. 'timestamp': int_or_none(data.get('created')),
  72. 'view_count': int_or_none(data.get('viewCount')),
  73. }