X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fbrightcove.py;h=031fe385d906dd8f4a53f8440955d325e5b0add1;hb=5cef4ff09b8e77daab03b1cca508a941b5fd5fa0;hp=b873dc0d4487565564d2eb1f262ab9cdac633139;hpb=7b0817e8e189ced899b64bfc3190b8f6218f04a3;p=youtube-dl diff --git a/youtube_dl/extractor/brightcove.py b/youtube_dl/extractor/brightcove.py index b873dc0d4..031fe385d 100644 --- a/youtube_dl/extractor/brightcove.py +++ b/youtube_dl/extractor/brightcove.py @@ -23,7 +23,6 @@ from ..utils import ( class BrightcoveIE(InfoExtractor): _VALID_URL = r'https?://.*brightcove\.com/(services|viewer).*\?(?P.*)' _FEDERATED_URL_TEMPLATE = 'http://c.brightcove.com/services/viewer/htmlFederated?%s' - _PLAYLIST_URL_TEMPLATE = 'http://c.brightcove.com/services/json/experience/runtime/?command=get_programming_for_experience&playerKey=%s' _TESTS = [ { @@ -70,7 +69,7 @@ class BrightcoveIE(InfoExtractor): 'description': 'md5:363109c02998fee92ec02211bd8000df', 'uploader': 'National Ballet of Canada', }, - }, + } ] @classmethod @@ -90,9 +89,12 @@ class BrightcoveIE(InfoExtractor): object_doc = xml.etree.ElementTree.fromstring(object_str) fv_el = find_xpath_attr(object_doc, './param', 'name', 'flashVars') - flashvars = dict( - (k, v[0]) - for k, v in compat_parse_qs(fv_el.attrib['value']).items()) + if fv_el is not None: + flashvars = dict( + (k, v[0]) + for k, v in compat_parse_qs(fv_el.attrib['value']).items()) + else: + flashvars = {} def find_param(name): if name in flashvars: @@ -125,20 +127,28 @@ class BrightcoveIE(InfoExtractor): @classmethod def _extract_brightcove_url(cls, webpage): - """Try to extract the brightcove url from the wepbage, returns None + """Try to extract the brightcove url from the webpage, returns None if it can't be found """ - m_brightcove = re.search( + urls = cls._extract_brightcove_urls(webpage) + return urls[0] if urls else None + + @classmethod + def _extract_brightcove_urls(cls, webpage): + """Return a list of all Brightcove URLs from the webpage """ + + url_m = re.search(r']+?class=([\'"])[^>]*?BrightcoveExperience.*?\1 | + [^>]+?class=[\'"][^>]*?BrightcoveExperience.*?[\'"] | [^>]*?>\s*''', webpage) - if m_brightcove is not None: - return cls._build_brighcove_url(m_brightcove.group()) - else: - return None + return [cls._build_brighcove_url(m) for m in matches] def _real_extract(self, url): url, smuggled_data = unsmuggle_url(url, {}) @@ -180,8 +190,9 @@ class BrightcoveIE(InfoExtractor): return self._extract_video_info(video_info) def _get_playlist_info(self, player_key): - playlist_info = self._download_webpage(self._PLAYLIST_URL_TEMPLATE % player_key, - player_key, 'Downloading playlist information') + info_url = 'http://c.brightcove.com/services/json/experience/runtime/?command=get_programming_for_experience&playerKey=%s' % player_key + playlist_info = self._download_webpage( + info_url, player_key, 'Downloading playlist information') json_data = json.loads(playlist_info) if 'videoList' not in json_data: @@ -195,7 +206,7 @@ class BrightcoveIE(InfoExtractor): def _extract_video_info(self, video_info): info = { 'id': compat_str(video_info['id']), - 'title': video_info['displayName'], + 'title': video_info['displayName'].strip(), 'description': video_info.get('shortDescription'), 'thumbnail': video_info.get('videoStillURL') or video_info.get('thumbnailURL'), 'uploader': video_info.get('publisherName'), @@ -230,6 +241,6 @@ class BrightcoveIE(InfoExtractor): else: return ad_info - if 'url' not in info: + if 'url' not in info and not info.get('formats'): raise ExtractorError('Unable to extract video url for %s' % info['id']) return info