logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

rtp.py (2248B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. js_to_json,
  7. )
  8. class RTPIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
  10. _TESTS = [{
  11. 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
  12. 'md5': 'e736ce0c665e459ddb818546220b4ef8',
  13. 'info_dict': {
  14. 'id': 'e174042',
  15. 'ext': 'mp3',
  16. 'title': 'Paixões Cruzadas',
  17. 'description': 'As paixões musicais de António Cartaxo e António Macedo',
  18. 'thumbnail': r're:^https?://.*\.jpg',
  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. config = self._parse_json(self._search_regex(
  30. r'(?s)RTPPlayer\(({.+?})\);', webpage,
  31. 'player config'), video_id, js_to_json)
  32. file_url = config['file']
  33. ext = determine_ext(file_url)
  34. if ext == 'm3u8':
  35. file_key = config.get('fileKey')
  36. formats = self._extract_m3u8_formats(
  37. file_url, video_id, 'mp4', 'm3u8_native',
  38. m3u8_id='hls', fatal=file_key)
  39. if file_key:
  40. formats.append({
  41. 'url': 'https://cdn-ondemand.rtp.pt' + file_key,
  42. 'preference': 1,
  43. })
  44. self._sort_formats(formats)
  45. else:
  46. formats = [{
  47. 'url': file_url,
  48. 'ext': ext,
  49. }]
  50. if config.get('mediaType') == 'audio':
  51. for f in formats:
  52. f['vcodec'] = 'none'
  53. return {
  54. 'id': video_id,
  55. 'title': title,
  56. 'formats': formats,
  57. 'description': self._html_search_meta(['description', 'twitter:description'], webpage),
  58. 'thumbnail': config.get('poster') or self._og_search_thumbnail(webpage),
  59. }