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.

60 lines
2.0 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]+)/(?P<id>[^/?#]+)/?'
  8. _TESTS = [{
  9. 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
  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. 'skip_download': True, # RTMP download
  19. },
  20. }, {
  21. 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. title = self._html_search_meta(
  28. 'twitter:title', webpage, display_name='title', fatal=True)
  29. description = self._html_search_meta('description', webpage)
  30. thumbnail = self._og_search_thumbnail(webpage)
  31. player_config = self._search_regex(
  32. r'(?s)RTPPLAY\.player\.newPlayer\(\s*(\{.*?\})\s*\)', webpage, 'player config')
  33. config = json.loads(js_to_json(player_config))
  34. path, ext = config.get('file').rsplit('.', 1)
  35. formats = [{
  36. 'app': config.get('application'),
  37. 'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path),
  38. 'page_url': url,
  39. 'url': 'rtmp://{streamer:s}/{application:s}'.format(**config),
  40. 'rtmp_live': config.get('live', False),
  41. 'ext': ext,
  42. 'vcodec': config.get('type') == 'audio' and 'none' or None,
  43. 'player_url': 'http://programas.rtp.pt/play/player.swf?v3',
  44. }]
  45. return {
  46. 'id': video_id,
  47. 'title': title,
  48. 'formats': formats,
  49. 'description': description,
  50. 'thumbnail': thumbnail,
  51. }