[Brightcove] Use extract_attributes, also handle data-video-id

Per @yan12125, use extract_attributes() since order may differ.

While preferring data-brightcove-video-id, use data-video-id if present,
to support #12005.
This commit is contained in:
John Hawkinson 2017-02-12 09:17:17 -05:00
parent b096e61098
commit e94df37ad6

View File

@ -17,6 +17,7 @@ from ..compat import (
from ..utils import (
determine_ext,
ExtractorError,
extract_attributes,
find_xpath_attr,
fix_xml_ampersands,
float_or_none,
@ -508,20 +509,22 @@ class BrightcoveNewIE(InfoExtractor):
'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
% (account_id, player_id, embed, video_id))
# <video data-brightcove-video-id="5320421710001" data-account="245991542" data-player="SJWAiyYWg" data-embed="default" class="video-js" controls itemscope itemtype="http://schema.org/VideoObject">
for video_id, account_id, player_id, embed in re.findall(
r'''(?sx)
<video[^>]+
data-brightcove-video-id=["\'](\d+|ref:[^"\']+)["\'].*?
data-account=["\'](\d+)["\'].*?
data-player=["\'](\w+)["\'].*?
data-embed=["\'](\w+)["\'].*?
</video>
''', webpage):
entries.append(
'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
% (account_id, player_id, embed, video_id))
# <video data-brightcove-video-id="5320421710001" data-account="245991542" data-player="SJWAiyYWg" data-embed="default" class="video-js" controls itemscope itemtype="http://schema.org/VideoObject">
for video in re.findall(r'(?i)(<video[^>]+>)', webpage):
attrs = extract_attributes(video)
video_id = attrs.get('data-brightcove-video-id')
if video_id is None:
video_id = attrs.get('data-video-id')
account_id = attrs.get('data-account')
player_id = attrs.get('data-player')
embed = attrs.get('data-embed')
if video_id and account_id and player_id and embed:
entries.append(
'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
% (account_id, player_id, embed, video_id))
return entries