]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/canalplus.py
Add an extractor for tlc.de (fixes #2748)
[yt-dlp.git] / youtube_dl / extractor / canalplus.py
CommitLineData
ad94a6fe 1# encoding: utf-8
ffca4b5c 2import re
ffca4b5c
JMF
3
4from .common import InfoExtractor
5from ..utils import unified_strdate
6
69545c2a 7
ffca4b5c 8class CanalplusIE(InfoExtractor):
ad94a6fe 9 _VALID_URL = r'https?://(www\.canalplus\.fr/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>\d+))'
ffca4b5c
JMF
10 _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s'
11 IE_NAME = u'canalplus.fr'
12
13 _TEST = {
ad94a6fe
JMF
14 u'url': u'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470',
15 u'file': u'922470.flv',
ffca4b5c 16 u'info_dict': {
ad94a6fe
JMF
17 u'title': u'Zapping - 26/08/13',
18 u'description': u'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013',
19 u'upload_date': u'20130826',
20 },
21 u'params': {
22 u'skip_download': True,
ffca4b5c 23 },
ffca4b5c
JMF
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
69545c2a 28 video_id = mobj.groupdict().get('id')
ad94a6fe
JMF
29 if video_id is None:
30 webpage = self._download_webpage(url, mobj.group('path'))
8efd15f4 31 video_id = self._search_regex(r'<canal:player videoId="(\d+)"', webpage, u'video id')
ffca4b5c 32 info_url = self._VIDEO_INFO_TEMPLATE % video_id
e26f8712 33 doc = self._download_xml(info_url,video_id,
ffca4b5c
JMF
34 u'Downloading video info')
35
36 self.report_extraction(video_id)
ffca4b5c
JMF
37 video_info = [video for video in doc if video.find('ID').text == video_id][0]
38 infos = video_info.find('INFOS')
39 media = video_info.find('MEDIA')
40 formats = [media.find('VIDEOS/%s' % format)
41 for format in ['BAS_DEBIT', 'HAUT_DEBIT', 'HD']]
42 video_url = [format.text for format in formats if format is not None][-1]
43
44 return {'id': video_id,
45 'title': u'%s - %s' % (infos.find('TITRAGE/TITRE').text,
46 infos.find('TITRAGE/SOUS_TITRE').text),
47 'url': video_url,
48 'ext': 'flv',
49 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
50 'thumbnail': media.find('IMAGES/GRAND').text,
ad94a6fe
JMF
51 'description': infos.find('DESCRIPTION').text,
52 'view_count': int(infos.find('NB_VUES').text),
ffca4b5c 53 }