]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/discovery.py
[dailymotion] Error spelling
[youtube-dl] / youtube_dl / extractor / discovery.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     parse_duration,
6     parse_iso8601,
7 )
8 from ..compat import compat_str
9
10
11 class DiscoveryIE(InfoExtractor):
12     _VALID_URL = r'http://www\.discovery\.com\/[a-zA-Z0-9\-]*/[a-zA-Z0-9\-]*/videos/(?P<id>[a-zA-Z0-9_\-]*)(?:\.htm)?'
13     _TESTS = [{
14         'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
15         'info_dict': {
16             'id': '20769',
17             'ext': 'mp4',
18             'title': 'Mission Impossible Outtakes',
19             'description': ('Watch Jamie Hyneman and Adam Savage practice being'
20                             ' each other -- to the point of confusing Jamie\'s dog -- and '
21                             'don\'t miss Adam moon-walking as Jamie ... behind Jamie\'s'
22                             ' back.'),
23             'duration': 156,
24             'timestamp': 1303099200,
25             'upload_date': '20110418',
26         },
27         'params': {
28             'skip_download': True,  # requires ffmpeg
29         }
30     }, {
31         'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mythbusters-the-simpsons',
32         'info_dict': {
33             'id': 'mythbusters-the-simpsons',
34             'title': 'MythBusters: The Simpsons',
35         },
36         'playlist_count': 9,
37     }]
38
39     def _real_extract(self, url):
40         video_id = self._match_id(url)
41         info = self._download_json(url + '?flat=1', video_id)
42
43         video_title = info.get('playlist_title') or info.get('video_title')
44
45         entries = [{
46             'id': compat_str(video_info['id']),
47             'formats': self._extract_m3u8_formats(
48                 video_info['src'], video_id, ext='mp4',
49                 note='Download m3u8 information for video %d' % (idx + 1)),
50             'title': video_info['title'],
51             'description': video_info.get('description'),
52             'duration': parse_duration(video_info.get('video_length')),
53             'webpage_url': video_info.get('href'),
54             'thumbnail': video_info.get('thumbnailURL'),
55             'alt_title': video_info.get('secondary_title'),
56             'timestamp': parse_iso8601(video_info.get('publishedDate')),
57         } for idx, video_info in enumerate(info['playlist'])]
58
59         return self.playlist_result(entries, video_id, video_title)