1 from __future__ import unicode_literals
3 from .common import InfoExtractor
8 from ..compat import compat_HTTPError
10 from .bbccouk import BBCCoUkIE
12 class BBCNewsIE(BBCCoUkIE):
15 _VALID_URL = r'https?://(?:www\.)?(?:bbc\.co\.uk|bbc\.com)/news/(?P<id>[^/]+)'
17 mediaselector_url = 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s'
20 'url': 'http://www.bbc.com/news/world-europe-32668511',
22 'id': 'world-europe-32668511',
23 'title': 'Russia stages massive WW2 parade despite Western boycott',
27 'url': 'http://www.bbc.com/news/business-28299555',
29 'id': 'business-28299555',
30 'title': 'Farnborough Airshow: Video highlights',
34 'url': 'http://www.bbc.com/news/world-europe-32041533',
39 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
40 'description': 'Germanwings plane crash site in aerial video - Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
44 'skip_download': True,
48 def _duration_str2int(self, str):
51 ret = re.match(r'^\d+$', str)
53 return int(ret.group(0))
54 ret = re.match(r'PT((?P<h>\d+)H)?((?P<m>\d+)M)?(?P<s>\d+)S$', str)
56 total=int(ret.group('s'))
58 total+=(int(ret.group('m'))*60)
60 total+=(int(ret.group('h'))*3600)
64 def _real_extract(self, url):
65 list_id = self._match_id(url)
66 webpage = self._download_webpage(url, list_id)
68 list_title = self._html_search_regex(r'<title>(.*?)(?:\s*-\s*BBC News)?</title>', webpage, 'list title')
70 pubdate = self._html_search_regex(r'"datePublished":\s*"(\d+-\d+-\d+)', webpage, 'date', default=None)
72 pubdate = pubdate.replace('-','')
75 # works with bbc.com/news/something-something-123456 articles
76 matches = re.findall(r"data-media-meta='({[^']+})'", webpage)
78 # stubbornly generic extractor for {json with "image":{allvideoshavethis},etc}
79 # in http://www.bbc.com/news/video_and_audio/international
80 matches = re.findall(r"({[^{}]+image\":{[^}]+}[^}]+})", webpage)
82 raise ExtractorError('No video found', expected=True)
85 jent = self._parse_json(ent,list_id)
87 programme_id = jent.get('externalId',None)
88 xml_url = jent.get('href', None)
90 title = jent['caption']
91 duration = self._duration_str2int(jent.get('duration',None))
92 description = list_title + ' - ' + jent.get('caption','')
94 if jent.has_key('image'):
95 thumbnail=jent['image'].get('href',None)
98 formats, subtitles = self._download_media_selector(programme_id)
101 # http://playlists.bbc.co.uk/news/(list_id)[ABC..]/playlist.sxml
102 xml = self._download_webpage(xml_url, programme_id, 'Downloading playlist.sxml for externalId (fallback)')
103 programme_id = self._search_regex(r'<mediator [^>]*identifier="(.+?)"', xml, 'playlist.sxml (externalId fallback)')
104 formats, subtitles = self._download_media_selector(programme_id)
106 raise ExtractorError('data-media-meta entry has no externalId or href value.')
108 self._sort_formats(formats)
112 'uploader': 'BBC News',
113 'upload_date': pubdate,
115 'description': description,
116 'thumbnail': thumbnail,
117 'duration': duration,
119 'subtitles': subtitles,
123 return self.playlist_result(ret, list_id, list_title)
124 raise ExtractorError('No video found', expected=True)