Proper support for changing User-Agents from IEs
authorPhilipp Hagemeister <phihag@phihag.de>
Sat, 12 Jan 2013 15:49:13 +0000 (16:49 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Sat, 12 Jan 2013 15:49:13 +0000 (16:49 +0100)
youtube_dl/FileDownloader.py
youtube_dl/InfoExtractors.py
youtube_dl/utils.py

index 51df4c1756dd101755804714dc562f69024b8cde..04ecd1ac5447cd306cc7d45bd67449e6f9bb66a4 100644 (file)
@@ -620,6 +620,8 @@ class FileDownloader(object):
 
         # Do not include the Accept-Encoding header
         headers = {'Youtubedl-no-compression': 'True'}
+        if 'user_agent' in info_dict:
+            headers['Youtubedl-user-agent'] = info_dict['user_agent']
         basic_request = compat_urllib_request.Request(url, None, headers)
         request = compat_urllib_request.Request(url, None, headers)
 
index 57267ccece2b63802bdaf7b043ab90259ae0ca49..9712480228a7c57e17d0ab80528a50806bb722c1 100755 (executable)
@@ -2209,6 +2209,7 @@ class BlipTVIE(InfoExtractor):
             cchar = '?'
         json_url = url + cchar + 'skin=json&version=2&no_wrap=1'
         request = compat_urllib_request.Request(json_url)
+        request.add_header('User-Agent', 'iTunes/10.6.1')
         self.report_extraction(mobj.group(1))
         info = None
         try:
@@ -2229,8 +2230,7 @@ class BlipTVIE(InfoExtractor):
                     'urlhandle': urlh
                 }
         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
-            self._downloader.trouble(u'ERROR: unable to download video info webpage: %s' % compat_str(err))
-            return
+            raise ExtractorError(u'ERROR: unable to download video info webpage: %s' % compat_str(err))
         if info is None: # Regular URL
             try:
                 json_code_bytes = urlh.read()
@@ -2263,13 +2263,13 @@ class BlipTVIE(InfoExtractor):
                     'format': data['media']['mimeType'],
                     'thumbnail': data['thumbnailUrl'],
                     'description': data['description'],
-                    'player_url': data['embedUrl']
+                    'player_url': data['embedUrl'],
+                    'user_agent': 'iTunes/10.6.1',
                 }
             except (ValueError,KeyError) as err:
                 self._downloader.trouble(u'ERROR: unable to parse video information: %s' % repr(err))
                 return
 
-        std_headers['User-Agent'] = 'iTunes/10.6.1'
         return [info]
 
 
index 0e37390a25d483fb9152b782431974391739f6fd..08be9e6373f6d4129327a6125b7d3b8c863273c0 100644 (file)
@@ -524,6 +524,11 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
             if 'Accept-encoding' in req.headers:
                 del req.headers['Accept-encoding']
             del req.headers['Youtubedl-no-compression']
+        if 'Youtubedl-user-agent' in req.headers:
+            if 'User-Agent' in req.headers:
+                del req.headers['User-Agent']
+            req.headers['User-Agent'] = req.headers['Youtubedl-user-agent']
+            del req.headers['Youtubedl-user-agent']
         return req
 
     def http_response(self, req, resp):