[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 ( from ..utils import (
determine_ext, determine_ext,
ExtractorError, ExtractorError,
extract_attributes,
find_xpath_attr, find_xpath_attr,
fix_xml_ampersands, fix_xml_ampersands,
float_or_none, float_or_none,
@ -508,21 +509,23 @@ class BrightcoveNewIE(InfoExtractor):
'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s' 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
% (account_id, player_id, embed, video_id)) % (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"> # <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( for video in re.findall(r'(?i)(<video[^>]+>)', webpage):
r'''(?sx) attrs = extract_attributes(video)
<video[^>]+
data-brightcove-video-id=["\'](\d+|ref:[^"\']+)["\'].*? video_id = attrs.get('data-brightcove-video-id')
data-account=["\'](\d+)["\'].*? if video_id is None:
data-player=["\'](\w+)["\'].*? video_id = attrs.get('data-video-id')
data-embed=["\'](\w+)["\'].*?
</video> account_id = attrs.get('data-account')
''', webpage): player_id = attrs.get('data-player')
embed = attrs.get('data-embed')
if video_id and account_id and player_id and embed:
entries.append( entries.append(
'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s' 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
% (account_id, player_id, embed, video_id)) % (account_id, player_id, embed, video_id))
return entries return entries
def _real_extract(self, url): def _real_extract(self, url):