from __future__ import unicode_literals
from .common import InfoExtractor
+from ..compat import compat_str
from ..utils import (
- determine_ext,
- int_or_none,
- parse_iso8601,
- unified_strdate,
+ try_get,
+ urljoin,
)
+
class PhilharmonieDeParisIE(InfoExtractor):
- _VALID_URL = r'http://live\.philharmoniedeparis\.fr/concert/(?P<id>\d+)(?:/|\.html)'
+ IE_DESC = 'Philharmonie de Paris'
+ _VALID_URL = r'''(?x)
+ https?://
+ (?:
+ live\.philharmoniedeparis\.fr/(?:[Cc]oncert/|misc/Playlist\.ashx\?id=)|
+ pad\.philharmoniedeparis\.fr/doc/CIMU/
+ )
+ (?P<id>\d+)
+ '''
_TESTS = [{
+ 'url': 'http://pad.philharmoniedeparis.fr/doc/CIMU/1086697/jazz-a-la-villette-knower',
+ 'md5': 'a0a4b195f544645073631cbec166a2c2',
+ 'info_dict': {
+ 'id': '1086697',
+ 'ext': 'mp4',
+ 'title': 'Jazz à la Villette : Knower',
+ },
+ }, {
'url': 'http://live.philharmoniedeparis.fr/concert/1032066.html',
'info_dict': {
'id': '1032066',
- 'ext': 'mp4',
- 'title': "Week-end Bach. Passion selon saint Jean. Akademie für alte Musik Berlin, Rias Kammerchor, René Jacobs",
- 'upload_date': '20150404',
- }
+ 'title': 'md5:0a031b81807b3593cffa3c9a87a167a0',
+ },
+ 'playlist_mincount': 2,
+ }, {
+ 'url': 'http://live.philharmoniedeparis.fr/Concert/1030324.html',
+ 'only_matching': True,
+ }, {
+ 'url': 'http://live.philharmoniedeparis.fr/misc/Playlist.ashx?id=1030324&track=&lang=fr',
+ 'only_matching': True,
}]
+ _LIVE_URL = 'https://live.philharmoniedeparis.fr'
def _real_extract(self, url):
video_id = self._match_id(url)
- webpage = self._download_webpage(url, video_id)
- fichier_nom = self._html_search_regex(r'\sflashvars\s*:\s*\{\s*fichier_nom\s*:\s*\'(.*?)\'\s*,', webpage, 'fichier_nom')
-
- playlist = self._download_xml('http://live.philharmoniedeparis.fr' + fichier_nom, video_id)
-
- concert = playlist.find('.//concert')
-
- formats = []
- info_dict = {
- 'id': video_id,
- 'title': concert.find('./titre').text,
- 'formats': formats,
- }
+ config = self._download_json(
+ '%s/otoPlayer/config.ashx' % self._LIVE_URL, video_id, query={
+ 'id': video_id,
+ 'lang': 'fr-FR',
+ })
- if concert.attrib.get('heure'):
- info_dict['timestamp'] = parse_iso8601(('%s-%s-%s%s') % (
- concert.attrib['date'][0:4],
- concert.attrib['date'][4:6],
- concert.attrib['date'][6:8],
- concert.attrib['heure']
- ))
- else:
- info_dict['upload_date'] = concert.attrib['date']
+ def extract_entry(source):
+ if not isinstance(source, dict):
+ return
+ title = source.get('title')
+ if not title:
+ return
+ files = source.get('files')
+ if not isinstance(files, dict):
+ return
+ format_urls = set()
+ formats = []
+ for format_id in ('mobile', 'desktop'):
+ format_url = try_get(
+ files, lambda x: x[format_id]['file'], compat_str)
+ if not format_url or format_url in format_urls:
+ continue
+ format_urls.add(format_url)
+ m3u8_url = urljoin(self._LIVE_URL, format_url)
+ formats.extend(self._extract_m3u8_formats(
+ m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
+ m3u8_id='hls', fatal=False))
+ if not formats:
+ return
+ self._sort_formats(formats)
+ return {
+ 'title': title,
+ 'formats': formats,
+ }
- fichiers = concert.find('./fichiers')
- for fichier in fichiers.findall('./fichier'):
- # Sometimes <ficher>s have no attributes at all. Skip them.
- if 'url' not in fichier.attrib:
- continue
+ thumbnail = urljoin(self._LIVE_URL, config.get('image'))
- formats.append({
- 'format_id': 'lq',
- 'url': fichiers.attrib['serveurstream'],
- 'ext': determine_ext(fichier.attrib['url']),
- 'play_path': fichier.attrib['url'],
- 'width': int_or_none(concert.attrib['largeur']),
- 'height': int_or_none(concert.attrib['hauteur']),
- 'quality': 1,
+ info = extract_entry(config)
+ if info:
+ info.update({
+ 'id': video_id,
+ 'thumbnail': thumbnail,
})
+ return info
- formats.append({
- 'format_id': 'hq',
- 'url': fichiers.attrib['serveurstream'],
- 'ext': determine_ext(fichier.attrib['url_hd']),
- 'play_path': fichier.attrib['url_hd'],
- 'width': int_or_none(concert.attrib['largeur_hd']),
- 'height': int_or_none(concert.attrib['hauteur_hd']),
- 'quality': 2,
- })
+ entries = []
+ for num, chapter in enumerate(config['chapters'], start=1):
+ entry = extract_entry(chapter)
+ entry['id'] = '%s-%d' % (video_id, num)
+ entries.append(entry)
- return info_dict
+ return self.playlist_result(entries, video_id, config.get('title'))