]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/discovery.py
[thisav] Simplify and use unicode literals
[youtube-dl] / 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://dsc\.discovery\.com\/[a-zA-Z0-9\-]*/[a-zA-Z0-9\-]*/videos/(?P<id>[a-zA-Z0-9\-]*)(.htm)?'
11     _TEST = {
12         'url': 'http://dsc.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
13         'file': '614784.mp4',
14         'md5': 'e12614f9ee303a6ccef415cb0793eba2',
15         'info_dict': {
16             'title': 'MythBusters: Mission Impossible Outtakes',
17             'description': ('Watch Jamie Hyneman and Adam Savage practice being'
18                 ' each other -- to the point of confusing Jamie\'s dog -- and '
19                 'don\'t miss Adam moon-walking as Jamie ... behind Jamie\'s'
20                 ' back.'),
21             'duration': 156,
22         },
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         video_id = mobj.group('id')
28         webpage = self._download_webpage(url, video_id)
29
30         video_list_json = self._search_regex(r'var videoListJSON = ({.*?});',
31             webpage, 'video list', flags=re.DOTALL)
32         video_list = json.loads(video_list_json)
33         info = video_list['clips'][0]
34         formats = []
35         for f in info['mp4']:
36             formats.append(
37                 {'url': f['src'], r'ext': r'mp4', 'tbr': int(f['bitrate'][:-1])})
38
39         return {
40             'id': info['contentId'],
41             'title': video_list['name'],
42             'formats': formats,
43             'description': info['videoCaption'],
44             'thumbnail': info.get('videoStillURL') or info.get('thumbnailURL'),
45             'duration': info['duration'],
46         }