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.

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