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.

154 lines
5.8 KiB

11 years ago
11 years ago
  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': 'c148457a27bdc9e5b1ffe081a7a8337b',
  34. 'info_dict': {
  35. 'id': '5624067',
  36. 'ext': 'mp4',
  37. 'duration': 3720,
  38. 'title': 'Les yeux dans les cieux - Mon homard au Canada',
  39. 'description': 'md5:d22ee46f5cc5bac0912e5a0c6d44a9f7',
  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(internal_id):
  95. return self._download_json(
  96. 'http://www.rts.ch/a/%s.html?f=json/article' % internal_id,
  97. video_id)
  98. all_info = download_json(video_id)
  99. # video_id extracted out of URL is not always a real id
  100. if 'video' not in all_info and 'audio' not in all_info:
  101. page = self._download_webpage(url, video_id)
  102. internal_id = self._html_search_regex(
  103. r'<(?:video|audio) data-id="([0-9]+)"', page,
  104. 'internal video id')
  105. all_info = download_json(internal_id)
  106. info = all_info['video']['JSONinfo'] if 'video' in all_info else all_info['audio']
  107. upload_timestamp = parse_iso8601(info.get('broadcast_date'))
  108. duration = info.get('duration') or info.get('cutout') or info.get('cutduration')
  109. if isinstance(duration, compat_str):
  110. duration = parse_duration(duration)
  111. view_count = info.get('plays')
  112. thumbnail = unescapeHTML(info.get('preview_image_url'))
  113. def extract_bitrate(url):
  114. return int_or_none(self._search_regex(
  115. r'-([0-9]+)k\.', url, 'bitrate', default=None))
  116. formats = [{
  117. 'format_id': fid,
  118. 'url': furl,
  119. 'tbr': extract_bitrate(furl),
  120. } for fid, furl in info['streams'].items()]
  121. if 'media' in info:
  122. formats.extend([{
  123. 'format_id': '%s-%sk' % (media['ext'], media['rate']),
  124. 'url': 'http://download-video.rts.ch/%s' % media['url'],
  125. 'tbr': media['rate'] or extract_bitrate(media['url']),
  126. } for media in info['media'] if media.get('rate')])
  127. self._sort_formats(formats)
  128. return {
  129. 'id': video_id,
  130. 'formats': formats,
  131. 'title': info['title'],
  132. 'description': info.get('intro'),
  133. 'duration': duration,
  134. 'view_count': view_count,
  135. 'uploader': info.get('programName'),
  136. 'timestamp': upload_timestamp,
  137. 'thumbnail': thumbnail,
  138. }