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.

186 lines
7.3 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]+)-(?P<display_id>.+?)\.html|play/tv/[^/]+/video/(?P<display_id_new>.+?)\?id=(?P<id_new>[0-9]+))'
  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. 'display_id': 'les-enfants-terribles',
  22. 'ext': 'mp4',
  23. 'duration': 1488,
  24. 'title': 'Les Enfants Terribles',
  25. 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.',
  26. 'uploader': 'Divers',
  27. 'upload_date': '19680921',
  28. 'timestamp': -40280400,
  29. 'thumbnail': 're:^https?://.*\.image',
  30. 'view_count': int,
  31. },
  32. },
  33. {
  34. 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html',
  35. 'md5': 'c148457a27bdc9e5b1ffe081a7a8337b',
  36. 'info_dict': {
  37. 'id': '5624067',
  38. 'display_id': 'entre-ciel-et-mer',
  39. 'ext': 'mp4',
  40. 'duration': 3720,
  41. 'title': 'Les yeux dans les cieux - Mon homard au Canada',
  42. 'description': 'md5:d22ee46f5cc5bac0912e5a0c6d44a9f7',
  43. 'uploader': 'Passe-moi les jumelles',
  44. 'upload_date': '20140404',
  45. 'timestamp': 1396635300,
  46. 'thumbnail': 're:^https?://.*\.image',
  47. 'view_count': int,
  48. },
  49. },
  50. {
  51. 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html',
  52. 'md5': 'b4326fecd3eb64a458ba73c73e91299d',
  53. 'info_dict': {
  54. 'id': '5745975',
  55. 'display_id': '1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski',
  56. 'ext': 'mp4',
  57. 'duration': 48,
  58. 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski',
  59. 'description': 'Hockey - Playoff',
  60. 'uploader': 'Hockey',
  61. 'upload_date': '20140403',
  62. 'timestamp': 1396556882,
  63. 'thumbnail': 're:^https?://.*\.image',
  64. 'view_count': int,
  65. },
  66. 'skip': 'Blocked outside Switzerland',
  67. },
  68. {
  69. 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html',
  70. 'md5': '9bb06503773c07ce83d3cbd793cebb91',
  71. 'info_dict': {
  72. 'id': '5745356',
  73. 'display_id': 'londres-cachee-par-un-epais-smog',
  74. 'ext': 'mp4',
  75. 'duration': 33,
  76. 'title': 'Londres cachée par un épais smog',
  77. 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.',
  78. 'uploader': 'Le Journal en continu',
  79. 'upload_date': '20140403',
  80. 'timestamp': 1396537322,
  81. 'thumbnail': 're:^https?://.*\.image',
  82. 'view_count': int,
  83. },
  84. },
  85. {
  86. 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html',
  87. 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae',
  88. 'info_dict': {
  89. 'id': '5706148',
  90. 'display_id': 'urban-hippie-de-damien-krisl-03-04-2014',
  91. 'ext': 'mp3',
  92. 'duration': 123,
  93. 'title': '"Urban Hippie", de Damien Krisl',
  94. 'description': 'Des Hippies super glam.',
  95. 'upload_date': '20140403',
  96. 'timestamp': 1396551600,
  97. },
  98. },
  99. {
  100. 'url': 'http://www.rts.ch/play/tv/-/video/le-19h30?id=6348260',
  101. 'md5': '968777c8779e5aa2434be96c54e19743',
  102. 'info_dict': {
  103. 'id': '6348260',
  104. 'display_id': 'le-19h30',
  105. 'ext': 'mp4',
  106. 'duration': 1796,
  107. 'title': 'Le 19h30',
  108. 'description': '',
  109. 'uploader': 'Le 19h30',
  110. 'upload_date': '20141201',
  111. 'timestamp': 1417458600,
  112. 'thumbnail': 're:^https?://.*\.image',
  113. 'view_count': int,
  114. },
  115. },
  116. {
  117. 'url': 'http://www.rts.ch/play/tv/le-19h30/video/le-chantier-du-nouveau-parlement-vaudois-a-permis-une-trouvaille-historique?id=6348280',
  118. 'only_matching': True,
  119. }
  120. ]
  121. def _real_extract(self, url):
  122. m = re.match(self._VALID_URL, url)
  123. video_id = m.group('id') or m.group('id_new')
  124. display_id = m.group('display_id') or m.group('display_id_new')
  125. def download_json(internal_id):
  126. return self._download_json(
  127. 'http://www.rts.ch/a/%s.html?f=json/article' % internal_id,
  128. display_id)
  129. all_info = download_json(video_id)
  130. # video_id extracted out of URL is not always a real id
  131. if 'video' not in all_info and 'audio' not in all_info:
  132. page = self._download_webpage(url, display_id)
  133. internal_id = self._html_search_regex(
  134. r'<(?:video|audio) data-id="([0-9]+)"', page,
  135. 'internal video id')
  136. all_info = download_json(internal_id)
  137. info = all_info['video']['JSONinfo'] if 'video' in all_info else all_info['audio']
  138. upload_timestamp = parse_iso8601(info.get('broadcast_date'))
  139. duration = info.get('duration') or info.get('cutout') or info.get('cutduration')
  140. if isinstance(duration, compat_str):
  141. duration = parse_duration(duration)
  142. view_count = info.get('plays')
  143. thumbnail = unescapeHTML(info.get('preview_image_url'))
  144. def extract_bitrate(url):
  145. return int_or_none(self._search_regex(
  146. r'-([0-9]+)k\.', url, 'bitrate', default=None))
  147. formats = [{
  148. 'format_id': fid,
  149. 'url': furl,
  150. 'tbr': extract_bitrate(furl),
  151. } for fid, furl in info['streams'].items()]
  152. if 'media' in info:
  153. formats.extend([{
  154. 'format_id': '%s-%sk' % (media['ext'], media['rate']),
  155. 'url': 'http://download-video.rts.ch/%s' % media['url'],
  156. 'tbr': media['rate'] or extract_bitrate(media['url']),
  157. } for media in info['media'] if media.get('rate')])
  158. self._sort_formats(formats)
  159. return {
  160. 'id': video_id,
  161. 'display_id': display_id,
  162. 'formats': formats,
  163. 'title': info['title'],
  164. 'description': info.get('intro'),
  165. 'duration': duration,
  166. 'view_count': view_count,
  167. 'uploader': info.get('programName'),
  168. 'timestamp': upload_timestamp,
  169. 'thumbnail': thumbnail,
  170. }