]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/discovery.py
[youtube] Add test with '};' in tags
[yt-dlp.git] / youtube_dl / extractor / discovery.py
CommitLineData
53bfd6b2 1from __future__ import unicode_literals
2
53bfd6b2 3from .common import InfoExtractor
9298d4e3 4from ..utils import (
65ba8b23 5 parse_duration,
9298d4e3 6 parse_iso8601,
9298d4e3 7)
65ba8b23 8from ..compat import compat_str
53bfd6b2 9
10
11class DiscoveryIE(InfoExtractor):
9298d4e3 12 _VALID_URL = r'http://www\.discovery\.com\/[a-zA-Z0-9\-]*/[a-zA-Z0-9\-]*/videos/(?P<id>[a-zA-Z0-9_\-]*)(?:\.htm)?'
65ba8b23 13 _TESTS = [{
cea2582d 14 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
53bfd6b2 15 'info_dict': {
65ba8b23
YCH
16 'id': '20769',
17 'ext': 'mp4',
9298d4e3 18 'title': 'Mission Impossible Outtakes',
9b05bd42 19 'description': ('Watch Jamie Hyneman and Adam Savage practice being'
9e1a5b84
JW
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.'),
9b05bd42 23 'duration': 156,
9298d4e3
PH
24 'timestamp': 1303099200,
25 'upload_date': '20110418',
9b05bd42 26 },
65ba8b23
YCH
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 }]
53bfd6b2 38
39 def _real_extract(self, url):
9298d4e3 40 video_id = self._match_id(url)
65ba8b23 41 info = self._download_json(url + '?flat=1', video_id)
9b05bd42 42
65ba8b23 43 video_title = info.get('playlist_title') or info.get('video_title')
53bfd6b2 44
65ba8b23
YCH
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)