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.

63 lines
2.0 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. )
  11. class RTSIE(InfoExtractor):
  12. IE_DESC = 'RTS.ch'
  13. _VALID_URL = r'^https?://(?:www\.)?rts\.ch/archives/tv/[^/]+/(?P<id>[0-9]+)-.*?\.html'
  14. _TEST = {
  15. 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html',
  16. 'md5': '753b877968ad8afaeddccc374d4256a5',
  17. 'info_dict': {
  18. 'id': '3449373',
  19. 'ext': 'mp4',
  20. 'duration': 1488,
  21. 'title': 'Les Enfants Terribles',
  22. 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.',
  23. 'uploader': 'Divers',
  24. 'upload_date': '19680921',
  25. 'timestamp': -40280400,
  26. 'thumbnail': 're:^https?://.*\.image'
  27. },
  28. }
  29. def _real_extract(self, url):
  30. m = re.match(self._VALID_URL, url)
  31. video_id = m.group('id')
  32. all_info = self._download_json(
  33. 'http://www.rts.ch/a/%s.html?f=json/article' % video_id, video_id)
  34. info = all_info['video']['JSONinfo']
  35. upload_timestamp = parse_iso8601(info.get('broadcast_date'))
  36. duration = parse_duration(info.get('duration'))
  37. thumbnail = unescapeHTML(info.get('preview_image_url'))
  38. formats = [{
  39. 'format_id': fid,
  40. 'url': furl,
  41. 'tbr': int_or_none(self._search_regex(
  42. r'-([0-9]+)k\.', furl, 'bitrate', default=None)),
  43. } for fid, furl in info['streams'].items()]
  44. self._sort_formats(formats)
  45. return {
  46. 'id': video_id,
  47. 'formats': formats,
  48. 'title': info['title'],
  49. 'description': info.get('intro'),
  50. 'duration': duration,
  51. 'uploader': info.get('programName'),
  52. 'timestamp': upload_timestamp,
  53. 'thumbnail': thumbnail,
  54. }