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.

57 lines
1.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import js_to_json
  6. class RTPIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/e(?P<id>[0-9]+)/?'
  8. _TEST = {
  9. 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
  10. 'info_dict': {
  11. 'id': '174042',
  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. 'skip_download': True, # RTMP download
  19. },
  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 = json.loads(js_to_json(player_config))
  31. path, ext = config.get('file').rsplit('.', 1)
  32. formats = [{
  33. 'app': config.get('application'),
  34. 'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path),
  35. 'page_url': url,
  36. 'url': 'rtmp://{streamer:s}/{application:s}'.format(**config),
  37. 'rtmp_live': config.get('live', False),
  38. 'ext': ext,
  39. 'vcodec': config.get('type') == 'audio' and 'none' or None,
  40. 'player_url': 'http://programas.rtp.pt/play/player.swf?v3',
  41. }]
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'formats': formats,
  46. 'description': description,
  47. 'thumbnail': thumbnail,
  48. }