aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-09-29 02:04:16 +0200
committerPhilipp Hagemeister <phihag@phihag.de>2014-09-29 02:04:16 +0200
commita1f934b171dcc8e1215ee30d0715ce562eb220e3 (patch)
treea90f0d6b0622ca00b6d9bbb3f5ec3f679834cd53
parenta43ee88c6f888196b47cb1e12463a64ada0ead12 (diff)
[youtube] Correct language cookie handling
-rw-r--r--youtube_dl/extractor/youtube.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index 61228817e..9041cfa87 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -655,9 +655,17 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
# Get video webpage
url = proto + '://www.youtube.com/watch?v=%s&gl=US&hl=en&has_verified=1' % video_id
- req = compat_urllib_request.Request(url)
- req.add_header('Cookie', 'PREF=hl=en')
- video_webpage = self._download_webpage(req, video_id)
+ pref_cookies = [
+ c for c in self._downloader.cookiejar
+ if c.domain == '.youtube.com' and c.name == 'PREF']
+ for pc in pref_cookies:
+ if 'hl=' in pc.value:
+ pc.value = re.sub(r'hl=[^&]+', 'hl=en', pc.value)
+ else:
+ if pc.value:
+ pc.value += '&'
+ pc.value += 'hl=en'
+ video_webpage = self._download_webpage(url, video_id)
# Attempt to extract SWF player URL
mobj = re.search(r'swfConfig.*?"(https?:\\/\\/.*?watch.*?-.*?\.swf)"', video_webpage)