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.

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