Use original Referer URL in Brightcove requests (Fixes #2110)
authorPhilipp Hagemeister <phihag@phihag.de>
Tue, 7 Jan 2014 04:34:14 +0000 (05:34 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Tue, 7 Jan 2014 04:34:14 +0000 (05:34 +0100)
youtube_dl/extractor/brightcove.py
youtube_dl/extractor/generic.py
youtube_dl/utils.py

index 4351565d5e8760c96ec0c7bc5d9119410bdb1103..4ba3f7c4200169145fd03ff44f3af3c753f47c74 100644 (file)
@@ -14,6 +14,7 @@ from ..utils import (
     compat_urllib_request,
 
     ExtractorError,
+    unsmuggle_url,
 )
 
 
@@ -121,6 +122,8 @@ class BrightcoveIE(InfoExtractor):
             return None
 
     def _real_extract(self, url):
+        url, smuggled_data = unsmuggle_url(url, {})
+
         # Change the 'videoId' and others field to '@videoPlayer'
         url = re.sub(r'(?<=[?&])(videoI(d|D)|bctid)', '%40videoPlayer', url)
         # Change bckey (used by bcove.me urls) to playerKey
@@ -131,9 +134,10 @@ class BrightcoveIE(InfoExtractor):
 
         videoPlayer = query.get('@videoPlayer')
         if videoPlayer:
-            return self._get_video_info(videoPlayer[0], query_str, query,
-                # We set the original url as the default 'Referer' header
-                referer=url)
+            # We set the original url as the default 'Referer' header
+            referer = smuggled_data.get('Referer', url)
+            return self._get_video_info(
+                videoPlayer[0], query_str, query, referer=referer)
         else:
             player_key = query['playerKey']
             return self._get_playlist_info(player_key[0])
index 2bfdf8f01f2ecd1659a8b0041f8ed06e9a54b73d..7d0e117de99eb2ff29992321a63e03dc820ad953 100644 (file)
@@ -225,7 +225,8 @@ class GenericIE(InfoExtractor):
         bc_url = BrightcoveIE._extract_brightcove_url(webpage)
         if bc_url is not None:
             self.to_screen('Brightcove video detected.')
-            return self.url_result(bc_url, 'Brightcove')
+            surl = smuggle_url(bc_url, {'Referer': url})
+            return self.url_result(surl, 'Brightcove')
 
         # Look for embedded (iframe) Vimeo player
         mobj = re.search(
index 918a127cae014377a3b463c810930be1f07a937f..0b0d1eb9000ae4875ce64cb10f8a5271b6abacb2 100644 (file)
@@ -1027,9 +1027,9 @@ def smuggle_url(url, data):
     return url + u'#' + sdata
 
 
-def unsmuggle_url(smug_url):
+def unsmuggle_url(smug_url, default=None):
     if not '#__youtubedl_smuggle' in smug_url:
-        return smug_url, None
+        return smug_url, default
     url, _, sdata = smug_url.rpartition(u'#')
     jsond = compat_parse_qs(sdata)[u'__youtubedl_smuggle'][0]
     data = json.loads(jsond)