logo

youtube-dl

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

philharmoniedeparis.py (3759B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. try_get,
  7. urljoin,
  8. )
  9. class PhilharmonieDeParisIE(InfoExtractor):
  10. IE_DESC = 'Philharmonie de Paris'
  11. _VALID_URL = r'''(?x)
  12. https?://
  13. (?:
  14. live\.philharmoniedeparis\.fr/(?:[Cc]oncert/|embed(?:app)?/|misc/Playlist\.ashx\?id=)|
  15. pad\.philharmoniedeparis\.fr/doc/CIMU/
  16. )
  17. (?P<id>\d+)
  18. '''
  19. _TESTS = [{
  20. 'url': 'http://pad.philharmoniedeparis.fr/doc/CIMU/1086697/jazz-a-la-villette-knower',
  21. 'md5': 'a0a4b195f544645073631cbec166a2c2',
  22. 'info_dict': {
  23. 'id': '1086697',
  24. 'ext': 'mp4',
  25. 'title': 'Jazz à la Villette : Knower',
  26. },
  27. }, {
  28. 'url': 'http://live.philharmoniedeparis.fr/concert/1032066.html',
  29. 'info_dict': {
  30. 'id': '1032066',
  31. 'title': 'md5:0a031b81807b3593cffa3c9a87a167a0',
  32. },
  33. 'playlist_mincount': 2,
  34. }, {
  35. 'url': 'http://live.philharmoniedeparis.fr/Concert/1030324.html',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'http://live.philharmoniedeparis.fr/misc/Playlist.ashx?id=1030324&track=&lang=fr',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'https://live.philharmoniedeparis.fr/embedapp/1098406/berlioz-fantastique-lelio-les-siecles-national-youth-choir-of.html?lang=fr-FR',
  42. 'only_matching': True,
  43. }, {
  44. 'url': 'https://live.philharmoniedeparis.fr/embed/1098406/berlioz-fantastique-lelio-les-siecles-national-youth-choir-of.html?lang=fr-FR',
  45. 'only_matching': True,
  46. }]
  47. _LIVE_URL = 'https://live.philharmoniedeparis.fr'
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. config = self._download_json(
  51. '%s/otoPlayer/config.ashx' % self._LIVE_URL, video_id, query={
  52. 'id': video_id,
  53. 'lang': 'fr-FR',
  54. })
  55. def extract_entry(source):
  56. if not isinstance(source, dict):
  57. return
  58. title = source.get('title')
  59. if not title:
  60. return
  61. files = source.get('files')
  62. if not isinstance(files, dict):
  63. return
  64. format_urls = set()
  65. formats = []
  66. for format_id in ('mobile', 'desktop'):
  67. format_url = try_get(
  68. files, lambda x: x[format_id]['file'], compat_str)
  69. if not format_url or format_url in format_urls:
  70. continue
  71. format_urls.add(format_url)
  72. m3u8_url = urljoin(self._LIVE_URL, format_url)
  73. formats.extend(self._extract_m3u8_formats(
  74. m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
  75. m3u8_id='hls', fatal=False))
  76. if not formats:
  77. return
  78. self._sort_formats(formats)
  79. return {
  80. 'title': title,
  81. 'formats': formats,
  82. }
  83. thumbnail = urljoin(self._LIVE_URL, config.get('image'))
  84. info = extract_entry(config)
  85. if info:
  86. info.update({
  87. 'id': video_id,
  88. 'thumbnail': thumbnail,
  89. })
  90. return info
  91. entries = []
  92. for num, chapter in enumerate(config['chapters'], start=1):
  93. entry = extract_entry(chapter)
  94. entry['id'] = '%s-%d' % (video_id, num)
  95. entries.append(entry)
  96. return self.playlist_result(entries, video_id, config.get('title'))