]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/brightcove.py
Imported Upstream version 2013.07.10
[youtubedl] / youtube_dl / extractor / brightcove.py
1 import re
2 import json
3
4 from .common import InfoExtractor
5
6 class BrightcoveIE(InfoExtractor):
7 _VALID_URL = r'http://.*brightcove\.com/.*\?(?P<query>.*videoPlayer=(?P<id>\d*).*)'
8
9 def _real_extract(self, url):
10 mobj = re.match(self._VALID_URL, url)
11 query = mobj.group('query')
12 video_id = mobj.group('id')
13
14 request_url = 'http://c.brightcove.com/services/viewer/htmlFederated?%s' % query
15 webpage = self._download_webpage(request_url, video_id)
16
17 self.report_extraction(video_id)
18 info = self._search_regex(r'var experienceJSON = ({.*?});', webpage, 'json')
19 info = json.loads(info)['data']
20 video_info = info['programmedContent']['videoPlayer']['mediaDTO']
21 renditions = video_info['renditions']
22 renditions = sorted(renditions, key=lambda r: r['size'])
23 best_format = renditions[-1]
24
25 return {'id': video_id,
26 'title': video_info['displayName'],
27 'url': best_format['defaultURL'],
28 'ext': 'mp4',
29 'description': video_info.get('shortDescription'),
30 'thumbnail': video_info.get('videoStillURL') or video_info.get('thumbnailURL'),
31 'uploader': video_info.get('publisherName'),
32 }