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.

98 lines
3.2 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. ExtractorError,
  7. )
  8. class RTBFIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)
  10. https?://(?:www\.)?rtbf\.be/
  11. (?:
  12. video/[^?]+\?.*\bid=|
  13. ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=|
  14. auvio/[^/]+\?.*id=
  15. )(?P<id>\d+)'''
  16. _TESTS = [{
  17. 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274',
  18. 'md5': '799f334ddf2c0a582ba80c44655be570',
  19. 'info_dict': {
  20. 'id': '1921274',
  21. 'ext': 'mp4',
  22. 'title': 'Les Diables au coeur (épisode 2)',
  23. 'description': 'Football - Diables Rouges',
  24. 'duration': 3099,
  25. 'upload_date': '20140425',
  26. 'timestamp': 1398456336,
  27. 'uploader': 'rtbfsport',
  28. }
  29. }, {
  30. # geo restricted
  31. 'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://www.rtbf.be/ouftivi/niouzz?videoId=2055858',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://www.rtbf.be/auvio/detail_jeudi-en-prime-siegfried-bracke?id=2102996',
  38. 'only_matching': True,
  39. }]
  40. _IMAGE_HOST = 'http://ds1.ds.static.rtbf.be'
  41. _PROVIDERS = {
  42. 'YOUTUBE': 'Youtube',
  43. 'DAILYMOTION': 'Dailymotion',
  44. 'VIMEO': 'Vimeo',
  45. }
  46. _QUALITIES = [
  47. ('mobile', 'SD'),
  48. ('web', 'MD'),
  49. ('high', 'HD'),
  50. ]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. data = self._download_json(
  54. 'http://www.rtbf.be/api/media/video?method=getVideoDetail&args[]=%s' % video_id, video_id)
  55. error = data.get('error')
  56. if error:
  57. raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
  58. data = data['data']
  59. provider = data.get('provider')
  60. if provider in self._PROVIDERS:
  61. return self.url_result(data['url'], self._PROVIDERS[provider])
  62. formats = []
  63. for key, format_id in self._QUALITIES:
  64. format_url = data.get(key + 'Url')
  65. if format_url:
  66. formats.append({
  67. 'format_id': format_id,
  68. 'url': format_url,
  69. })
  70. thumbnails = []
  71. for thumbnail_id, thumbnail_url in data.get('thumbnail', {}).items():
  72. if thumbnail_id != 'default':
  73. thumbnails.append({
  74. 'url': self._IMAGE_HOST + thumbnail_url,
  75. 'id': thumbnail_id,
  76. })
  77. return {
  78. 'id': video_id,
  79. 'formats': formats,
  80. 'title': data['title'],
  81. 'description': data.get('description') or data.get('subtitle'),
  82. 'thumbnails': thumbnails,
  83. 'duration': data.get('duration') or data.get('realDuration'),
  84. 'timestamp': int_or_none(data.get('created')),
  85. 'view_count': int_or_none(data.get('viewCount')),
  86. 'uploader': data.get('channel'),
  87. 'tags': data.get('tags'),
  88. }