Merge remote-tracking branch 'rzhxeo/embedly'
[youtube-dl] / youtube_dl / extractor / nbc.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import find_xpath_attr, compat_str
7
8
9 class NBCIE(InfoExtractor):
10     _VALID_URL = r'http://www\.nbc\.com/[^/]+/video/[^/]+/(?P<id>n?\d+)'
11
12     _TEST = {
13         'url': 'http://www.nbc.com/chicago-fire/video/i-am-a-firefighter/2734188',
14         'md5': '54d0fbc33e0b853a65d7b4de5c06d64e',
15         'info_dict': {
16             'id': 'u1RInQZRN7QJ',
17             'ext': 'flv',
18             'title': 'I Am a Firefighter',
19             'description': 'An emergency puts Dawson\'sf irefighter skills to the ultimate test in this four-part digital series.',
20         },
21     }
22
23     def _real_extract(self, url):
24         mobj = re.match(self._VALID_URL, url)
25         video_id = mobj.group('id')
26         webpage = self._download_webpage(url, video_id)
27         theplatform_url = self._search_regex('class="video-player video-player-full" data-mpx-url="(.*?)"', webpage, 'theplatform url')
28         if theplatform_url.startswith('//'):
29             theplatform_url = 'http:' + theplatform_url
30         return self.url_result(theplatform_url)
31
32
33 class NBCNewsIE(InfoExtractor):
34     _VALID_URL = r'https?://www\.nbcnews\.com/video/.+?/(?P<id>\d+)'
35
36     _TEST = {
37         'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
38         'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
39         'info_dict': {
40             'id': '52753292',
41             'ext': 'flv',
42             'title': 'Crew emerges after four-month Mars food study',
43             'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
44         },
45     }
46
47     def _real_extract(self, url):
48         mobj = re.match(self._VALID_URL, url)
49         video_id = mobj.group('id')
50         all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
51         info = all_info.find('video')
52
53         return {
54             'id': video_id,
55             'title': info.find('headline').text,
56             'ext': 'flv',
57             'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
58             'description': compat_str(info.find('caption').text),
59             'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
60         }