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.

89 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class RTPIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
  7. _TESTS = [{
  8. 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
  9. 'md5': 'e736ce0c665e459ddb818546220b4ef8',
  10. 'info_dict': {
  11. 'id': 'e174042',
  12. 'ext': 'mp3',
  13. 'title': 'Paixões Cruzadas',
  14. 'description': 'As paixões musicais de António Cartaxo e António Macedo',
  15. 'thumbnail': 're:^https?://.*\.jpg',
  16. },
  17. 'params': {
  18. # rtmp download
  19. 'skip_download': True,
  20. },
  21. }, {
  22. 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. title = self._html_search_meta(
  29. 'twitter:title', webpage, display_name='title', fatal=True)
  30. description = self._html_search_meta('description', webpage)
  31. thumbnail = self._og_search_thumbnail(webpage)
  32. player_config = self._search_regex(
  33. r'(?s)RTPPLAY\.player\.newPlayer\(\s*(\{.*?\})\s*\)', webpage, 'player config')
  34. config = self._parse_json(player_config, video_id)
  35. path, ext = config.get('file').rsplit('.', 1)
  36. formats = [{
  37. 'format_id': 'rtmp',
  38. 'ext': ext,
  39. 'vcodec': config.get('type') == 'audio' and 'none' or None,
  40. 'preference': -2,
  41. 'url': 'rtmp://{streamer:s}/{application:s}'.format(**config),
  42. 'app': config.get('application'),
  43. 'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path),
  44. 'page_url': url,
  45. 'rtmp_live': config.get('live', False),
  46. 'player_url': 'http://programas.rtp.pt/play/player.swf?v3',
  47. 'rtmp_real_time': True,
  48. }]
  49. # Construct regular HTTP download URLs
  50. replacements = {
  51. 'audio': {
  52. 'format_id': 'mp3',
  53. 'pattern': r'^nas2\.share/wavrss/',
  54. 'repl': 'http://rsspod.rtp.pt/podcasts/',
  55. 'vcodec': 'none',
  56. },
  57. 'video': {
  58. 'format_id': 'mp4_h264',
  59. 'pattern': r'^nas2\.share/h264/',
  60. 'repl': 'http://rsspod.rtp.pt/videocasts/',
  61. 'vcodec': 'h264',
  62. },
  63. }
  64. r = replacements[config['type']]
  65. if re.match(r['pattern'], config['file']) is not None:
  66. formats.append({
  67. 'format_id': r['format_id'],
  68. 'url': re.sub(r['pattern'], r['repl'], config['file']),
  69. 'vcodec': r['vcodec'],
  70. })
  71. self._sort_formats(formats)
  72. return {
  73. 'id': video_id,
  74. 'title': title,
  75. 'formats': formats,
  76. 'description': description,
  77. 'thumbnail': thumbnail,
  78. }