]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/nbc.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
17 class NBCIE(InfoExtractor
):
18 _VALID_URL
= r
'http://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
22 'url': 'http://www.nbc.com/chicago-fire/video/i-am-a-firefighter/2734188',
23 # md5 checksum is not stable
27 'title': 'I Am a Firefighter',
28 'description': 'An emergency puts Dawson\'sf irefighter skills to the ultimate test in this four-part digital series.',
32 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
36 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
37 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
39 'skip': 'Only works from US',
43 def _real_extract(self
, url
):
44 video_id
= self
._match
_id
(url
)
45 webpage
= self
._download
_webpage
(url
, video_id
)
46 theplatform_url
= self
._search
_regex
(
47 '(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
48 webpage
, 'theplatform url').replace('_no_endcard', '')
49 if theplatform_url
.startswith('//'):
50 theplatform_url
= 'http:' + theplatform_url
51 return self
.url_result(theplatform_url
)
54 class NBCNewsIE(InfoExtractor
):
55 _VALID_URL
= r
'''(?x)https?://www\.nbcnews\.com/
56 ((video/.+?/(?P<id>\d+))|
57 ((?P<program>feature|nightly-news)/[^/]+/(?P<title>.+)))
62 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
63 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
67 'title': 'Crew emerges after four-month Mars food study',
68 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
72 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
73 'md5': 'b2421750c9f260783721d898f4c42063',
77 'title': 'How Twitter Reacted To The Snowden Interview',
78 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
80 'add_ie': ['ThePlatform'],
83 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
84 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
88 'title': 'FULL EPISODE: Family Business',
89 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
93 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
94 'md5': 'b5dda8cddd8650baa0dcb616dd2cf60d',
98 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
99 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
104 def _real_extract(self
, url
):
105 mobj
= re
.match(self
._VALID
_URL
, url
)
106 video_id
= mobj
.group('id')
107 if video_id
is not None:
108 all_info
= self
._download
_xml
('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id
, video_id
)
109 info
= all_info
.find('video')
113 'title': info
.find('headline').text
,
115 'url': find_xpath_attr(info
, 'media', 'type', 'flashVideo').text
,
116 'description': compat_str(info
.find('caption').text
),
117 'thumbnail': find_xpath_attr(info
, 'media', 'type', 'thumbnail').text
,
120 # "feature" and "nightly-news" pages use theplatform.com
121 title
= mobj
.group('title')
122 webpage
= self
._download
_webpage
(url
, title
)
123 program
= mobj
.group('program')
124 if program
== 'feature':
125 bootstrap_json
= self
._search
_regex
(
126 r
'var bootstrapJson = ({.+})\s*$', webpage
, 'bootstrap json',
130 bootstrap_json
= self
._search
_regex
(
131 r
'var playlistData = ({.+});\s*$', webpage
, 'playlist data',
133 bootstrap
= json
.loads(bootstrap_json
)
134 info
= bootstrap
['results'][0]['video']
135 mpxid
= info
['mpxId']
138 info
['fallbackPlaylistUrl'],
139 info
['associatedPlaylistUrl'],
142 for base_url
in base_urls
:
145 playlist_url
= base_url
+ '?form=MPXNBCNewsAPI'
148 all_videos
= self
._download
_json
(playlist_url
, title
)
149 except ExtractorError
as ee
:
150 if isinstance(ee
.cause
, compat_HTTPError
):
154 if not all_videos
or 'videos' not in all_videos
:
158 info
= next(v
for v
in all_videos
['videos'] if v
['mpxId'] == mpxid
)
160 except StopIteration:
164 raise ExtractorError('Could not find video in playlists')
168 # We get the best quality video
169 'url': info
['videoAssets'][-1]['publicUrl'],
170 'ie_key': 'ThePlatform',