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.

85 lines
2.9 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. }, {
  18. 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
  19. 'only_matching': True,
  20. }]
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. webpage = self._download_webpage(url, video_id)
  24. title = self._html_search_meta(
  25. 'twitter:title', webpage, display_name='title', fatal=True)
  26. description = self._html_search_meta('description', webpage)
  27. thumbnail = self._og_search_thumbnail(webpage)
  28. player_config = self._search_regex(
  29. r'(?s)RTPPLAY\.player\.newPlayer\(\s*(\{.*?\})\s*\)', webpage, 'player config')
  30. config = self._parse_json(player_config, video_id)
  31. path, ext = config.get('file').rsplit('.', 1)
  32. formats = [{
  33. 'format_id': 'rtmp',
  34. 'ext': ext,
  35. 'vcodec': config.get('type') == 'audio' and 'none' or None,
  36. 'preference': -2,
  37. 'url': 'rtmp://{streamer:s}/{application:s}'.format(**config),
  38. 'app': config.get('application'),
  39. 'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path),
  40. 'page_url': url,
  41. 'rtmp_live': config.get('live', False),
  42. 'player_url': 'http://programas.rtp.pt/play/player.swf?v3',
  43. 'rtmp_real_time': True,
  44. }]
  45. # Construct regular HTTP download URLs
  46. replacements = {
  47. 'audio': {
  48. 'format_id': 'mp3',
  49. 'pattern': r'^nas2\.share/wavrss/',
  50. 'repl': 'http://rsspod.rtp.pt/podcasts/',
  51. 'vcodec': 'none',
  52. },
  53. 'video': {
  54. 'format_id': 'mp4_h264',
  55. 'pattern': r'^nas2\.share/h264/',
  56. 'repl': 'http://rsspod.rtp.pt/videocasts/',
  57. 'vcodec': 'h264',
  58. },
  59. }
  60. r = replacements[config['type']]
  61. if re.match(r['pattern'], config['file']) is not None:
  62. formats.append({
  63. 'format_id': r['format_id'],
  64. 'url': re.sub(r['pattern'], r['repl'], config['file']),
  65. 'vcodec': r['vcodec'],
  66. })
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'title': title,
  71. 'formats': formats,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. }