]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/discovery.py
Prepare new release.
[youtubedl] / 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'''(?x)https?://(?:www\.)?(?:
13 discovery|
14 investigationdiscovery|
15 discoverylife|
16 animalplanet|
17 ahctv|
18 destinationamerica|
19 sciencechannel|
20 tlc|
21 velocity
22 )\.com/(?:[^/]+/)*(?P<id>[^./?#]+)'''
23 _TESTS = [{
24 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
25 'info_dict': {
26 'id': '20769',
27 'ext': 'mp4',
28 'title': 'Mission Impossible Outtakes',
29 'description': ('Watch Jamie Hyneman and Adam Savage practice being'
30 ' each other -- to the point of confusing Jamie\'s dog -- and '
31 'don\'t miss Adam moon-walking as Jamie ... behind Jamie\'s'
32 ' back.'),
33 'duration': 156,
34 'timestamp': 1302032462,
35 'upload_date': '20110405',
36 'uploader_id': '103207',
37 },
38 'params': {
39 'skip_download': True, # requires ffmpeg
40 }
41 }, {
42 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mythbusters-the-simpsons',
43 'info_dict': {
44 'id': 'mythbusters-the-simpsons',
45 'title': 'MythBusters: The Simpsons',
46 },
47 'playlist_mincount': 10,
48 }, {
49 'url': 'http://www.animalplanet.com/longfin-eels-maneaters/',
50 'info_dict': {
51 'id': '78326',
52 'ext': 'mp4',
53 'title': 'Longfin Eels: Maneaters?',
54 'description': 'Jeremy Wade tests whether or not New Zealand\'s longfin eels are man-eaters by covering himself in fish guts and getting in the water with them.',
55 'upload_date': '20140725',
56 'timestamp': 1406246400,
57 'duration': 116,
58 'uploader_id': '103207',
59 },
60 'params': {
61 'skip_download': True, # requires ffmpeg
62 }
63 }]
64
65 def _real_extract(self, url):
66 display_id = self._match_id(url)
67 info = self._download_json(url + '?flat=1', display_id)
68
69 video_title = info.get('playlist_title') or info.get('video_title')
70
71 entries = []
72
73 for idx, video_info in enumerate(info['playlist']):
74 subtitles = {}
75 caption_url = video_info.get('captionsUrl')
76 if caption_url:
77 subtitles = {
78 'en': [{
79 'url': caption_url,
80 }]
81 }
82
83 entries.append({
84 '_type': 'url_transparent',
85 'url': 'http://players.brightcove.net/103207/default_default/index.html?videoId=ref:%s' % video_info['referenceId'],
86 'id': compat_str(video_info['id']),
87 'title': video_info['title'],
88 'description': video_info.get('description'),
89 'duration': parse_duration(video_info.get('video_length')),
90 'webpage_url': video_info.get('href') or video_info.get('url'),
91 'thumbnail': video_info.get('thumbnailURL'),
92 'alt_title': video_info.get('secondary_title'),
93 'timestamp': parse_iso8601(video_info.get('publishedDate')),
94 'subtitles': subtitles,
95 })
96
97 return self.playlist_result(entries, display_id, video_title)