1 from __future__ import unicode_literals
3 from .common import InfoExtractor
9 from ..compat import compat_HTTPError
11 from .bbccouk import BBCCoUkIE
13 class BBCNewsIE(BBCCoUkIE):
16 _VALID_URL = r'https?://(?:www\.)?(?:bbc\.co\.uk|bbc\.com)/news/(?P<id>[^/]+)'
18 mediaselector_url = 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s'
21 'url': 'http://www.bbc.com/news/world-europe-32668511',
23 'id': 'world-europe-32668511',
24 'title': 'Russia stages massive WW2 parade despite Western boycott',
28 'url': 'http://www.bbc.com/news/business-28299555',
30 'id': 'business-28299555',
31 'title': 'Farnborough Airshow: Video highlights',
35 'url': 'http://www.bbc.com/news/world-europe-32041533',
40 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
41 'description': 'Germanwings plane crash site in aerial video - Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
45 'skip_download': True,
49 def _real_extract(self, url):
50 list_id = self._match_id(url)
51 webpage = self._download_webpage(url, list_id)
53 list_title = self._html_search_regex(r'<title>(.*?)(?:\s*-\s*BBC News)?</title>', webpage, 'list title')
55 pubdate = self._html_search_regex(r'"datePublished":\s*"(\d+-\d+-\d+)', webpage, 'date', default=None)
57 pubdate = pubdate.replace('-','')
60 # works with bbc.com/news/something-something-123456 articles
61 matches = re.findall(r"data-media-meta='({[^']+})'", webpage)
63 # stubbornly generic extractor for {json with "image":{allvideoshavethis},etc}
64 # in http://www.bbc.com/news/video_and_audio/international
65 matches = re.findall(r"({[^{}]+image\":{[^}]+}[^}]+})", webpage)
67 raise ExtractorError('No video found', expected=True)
70 jent = self._parse_json(ent,list_id)
72 programme_id = jent.get('externalId',None)
73 xml_url = jent.get('href', None)
75 title = jent['caption']
76 duration = parse_duration(jent.get('duration',None))
77 description = list_title + ' - ' + jent.get('caption','')
79 if jent.has_key('image'):
80 thumbnail=jent['image'].get('href',None)
83 formats, subtitles = self._download_media_selector(programme_id)
86 # http://playlists.bbc.co.uk/news/(list_id)[ABC..]/playlist.sxml
87 xml = self._download_webpage(xml_url, programme_id, 'Downloading playlist.sxml for externalId (fallback)')
88 programme_id = self._search_regex(r'<mediator [^>]*identifier="(.+?)"', xml, 'playlist.sxml (externalId fallback)')
89 formats, subtitles = self._download_media_selector(programme_id)
91 raise ExtractorError('data-media-meta entry has no externalId or href value.')
93 self._sort_formats(formats)
97 'uploader': 'BBC News',
98 'upload_date': pubdate,
100 'description': description,
101 'thumbnail': thumbnail,
102 'duration': duration,
104 'subtitles': subtitles,
108 return self.playlist_result(ret, list_id, list_title)
109 raise ExtractorError('No video found', expected=True)