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.

151 lines
5.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_duration,
  8. parse_iso8601,
  9. unescapeHTML,
  10. compat_str,
  11. )
  12. class RTSIE(InfoExtractor):
  13. IE_DESC = 'RTS.ch'
  14. _VALID_URL = r'^https?://(?:www\.)?rts\.ch/(?:[^/]+/){2,}(?P<id>[0-9]+)-.*?\.html'
  15. _TESTS = [
  16. {
  17. 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html',
  18. 'md5': '753b877968ad8afaeddccc374d4256a5',
  19. 'info_dict': {
  20. 'id': '3449373',
  21. 'ext': 'mp4',
  22. 'duration': 1488,
  23. 'title': 'Les Enfants Terribles',
  24. 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.',
  25. 'uploader': 'Divers',
  26. 'upload_date': '19680921',
  27. 'timestamp': -40280400,
  28. 'thumbnail': 're:^https?://.*\.image'
  29. },
  30. },
  31. {
  32. 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html',
  33. 'md5': 'c197f0b2421995c63a64cc73d800f42e',
  34. 'info_dict': {
  35. 'id': '5738317',
  36. 'ext': 'mp4',
  37. 'duration': 55,
  38. 'title': 'Bande de lancement de Passe-moi les jumelles',
  39. 'description': '',
  40. 'uploader': 'Passe-moi les jumelles',
  41. 'upload_date': '20140404',
  42. 'timestamp': 1396635300,
  43. 'thumbnail': 're:^https?://.*\.image'
  44. },
  45. },
  46. {
  47. 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html',
  48. 'md5': 'b4326fecd3eb64a458ba73c73e91299d',
  49. 'info_dict': {
  50. 'id': '5745975',
  51. 'ext': 'mp4',
  52. 'duration': 48,
  53. 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski',
  54. 'description': 'Hockey - Playoff',
  55. 'uploader': 'Hockey',
  56. 'upload_date': '20140403',
  57. 'timestamp': 1396556882,
  58. 'thumbnail': 're:^https?://.*\.image'
  59. },
  60. 'skip': 'Blocked outside Switzerland',
  61. },
  62. {
  63. 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html',
  64. 'md5': '9bb06503773c07ce83d3cbd793cebb91',
  65. 'info_dict': {
  66. 'id': '5745356',
  67. 'ext': 'mp4',
  68. 'duration': 33,
  69. 'title': 'Londres cachée par un épais smog',
  70. 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.',
  71. 'uploader': 'Le Journal en continu',
  72. 'upload_date': '20140403',
  73. 'timestamp': 1396537322,
  74. 'thumbnail': 're:^https?://.*\.image'
  75. },
  76. },
  77. {
  78. 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html',
  79. 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae',
  80. 'info_dict': {
  81. 'id': '5706148',
  82. 'ext': 'mp3',
  83. 'duration': 123,
  84. 'title': '"Urban Hippie", de Damien Krisl',
  85. 'description': 'Des Hippies super glam.',
  86. 'upload_date': '20140403',
  87. 'timestamp': 1396551600,
  88. },
  89. },
  90. ]
  91. def _real_extract(self, url):
  92. m = re.match(self._VALID_URL, url)
  93. video_id = m.group('id')
  94. def download_json(video_id):
  95. return self._download_json(
  96. 'http://www.rts.ch/a/%s.html?f=json/article' % video_id, video_id)
  97. all_info = download_json(video_id)
  98. # video_id extracted out of URL is not always a real id
  99. if 'video' not in all_info and 'audio' not in all_info:
  100. page = self._download_webpage(url, video_id)
  101. video_id = self._html_search_regex(r'<(?:video|audio) data-id="(\d+)"', page, 'video id')
  102. all_info = download_json(video_id)
  103. info = all_info['video']['JSONinfo'] if 'video' in all_info else all_info['audio']
  104. upload_timestamp = parse_iso8601(info.get('broadcast_date'))
  105. duration = info.get('duration') or info.get('cutout') or info.get('cutduration')
  106. if isinstance(duration, compat_str):
  107. duration = parse_duration(duration)
  108. view_count = info.get('plays')
  109. thumbnail = unescapeHTML(info.get('preview_image_url'))
  110. def extract_bitrate(url):
  111. return int_or_none(self._search_regex(
  112. r'-([0-9]+)k\.', url, 'bitrate', default=None))
  113. formats = [{
  114. 'format_id': fid,
  115. 'url': furl,
  116. 'tbr': extract_bitrate(furl),
  117. } for fid, furl in info['streams'].items()]
  118. if 'media' in info:
  119. formats.extend([{
  120. 'format_id': '%s-%sk' % (media['ext'], media['rate']),
  121. 'url': 'http://download-video.rts.ch/%s' % media['url'],
  122. 'tbr': media['rate'] or extract_bitrate(media['url']),
  123. } for media in info['media'] if media.get('rate')])
  124. self._sort_formats(formats)
  125. return {
  126. 'id': video_id,
  127. 'formats': formats,
  128. 'title': info['title'],
  129. 'description': info.get('intro'),
  130. 'duration': duration,
  131. 'view_count': view_count,
  132. 'uploader': info.get('programName'),
  133. 'timestamp': upload_timestamp,
  134. 'thumbnail': thumbnail,
  135. }