]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/discovery.py
debian/changelog: Start new release.
[youtubedl] / youtube_dl / extractor / discovery.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7
8
9 class DiscoveryIE(InfoExtractor):
10 _VALID_URL = r'http://www\.discovery\.com\/[a-zA-Z0-9\-]*/[a-zA-Z0-9\-]*/videos/(?P<id>[a-zA-Z0-9\-]*)(.htm)?'
11 _TEST = {
12 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
13 'md5': 'e12614f9ee303a6ccef415cb0793eba2',
14 'info_dict': {
15 'id': '614784',
16 'ext': 'mp4',
17 'title': 'MythBusters: Mission Impossible Outtakes',
18 'description': ('Watch Jamie Hyneman and Adam Savage practice being'
19 ' each other -- to the point of confusing Jamie\'s dog -- and '
20 'don\'t miss Adam moon-walking as Jamie ... behind Jamie\'s'
21 ' back.'),
22 'duration': 156,
23 },
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.group('id')
29 webpage = self._download_webpage(url, video_id)
30
31 video_list_json = self._search_regex(r'var videoListJSON = ({.*?});',
32 webpage, 'video list', flags=re.DOTALL)
33 video_list = json.loads(video_list_json)
34 info = video_list['clips'][0]
35 formats = []
36 for f in info['mp4']:
37 formats.append(
38 {'url': f['src'], 'ext': 'mp4', 'tbr': int(f['bitrate'][:-1])})
39
40 return {
41 'id': info['contentId'],
42 'title': video_list['name'],
43 'formats': formats,
44 'description': info['videoCaption'],
45 'thumbnail': info.get('videoStillURL') or info.get('thumbnailURL'),
46 'duration': info['duration'],
47 }