aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Rudloff <contact@rudloff.pro>2013-08-28 12:10:34 +0200
committerPierre Rudloff <contact@rudloff.pro>2013-08-28 12:10:34 +0200
commitb7f89fe692109368e35b4a0723e1044ed6b51e1e (patch)
tree3185112c5cb7d688e77b43f73e6cfe0d3dabdad4
parent1301a0dd426a88ed39d38ac6ad04e9000c7811a4 (diff)
parentae3531adf926998d42d1fb52453491c85e33b5f0 (diff)
downloadyoutube-dl-b7f89fe692109368e35b4a0723e1044ed6b51e1e.tar.xz
Merge remote-tracking branch 'upstream/master'
-rw-r--r--youtube_dl/extractor/generic.py7
-rw-r--r--youtube_dl/utils.py19
2 files changed, 23 insertions, 3 deletions
diff --git a/youtube_dl/extractor/generic.py b/youtube_dl/extractor/generic.py
index d034a11bb..bfc9bff49 100644
--- a/youtube_dl/extractor/generic.py
+++ b/youtube_dl/extractor/generic.py
@@ -166,7 +166,12 @@ class GenericIE(InfoExtractor):
if video_url.startswith('//'):
video_url = compat_urllib_parse_urlparse(url).scheme + ':' + video_url
if '://' not in video_url:
- video_url = url + ('' if url.endswith('/') else '/') + video_url
+ up = compat_urllib_parse_urlparse(url)
+ if video_url.startswith('/'):
+ video_url = up.scheme + '://' + up.netloc + video_url
+ else: # relative path
+ video_url = (up.scheme + '://' + up.netloc +
+ up.path.rpartition('/')[0] + '/' + video_url)
video_id = os.path.basename(video_url)
# here's a fun little line of code for you:
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index e6fa634a7..be788cf5a 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -628,8 +628,23 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
old_resp = resp
# gzip
if resp.headers.get('Content-encoding', '') == 'gzip':
- gz = gzip.GzipFile(fileobj=io.BytesIO(resp.read()), mode='r')
- resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
+ content = resp.read()
+ gz = gzip.GzipFile(fileobj=io.BytesIO(content), mode='rb')
+ try:
+ uncompressed = io.BytesIO(gz.read())
+ except IOError as original_ioerror:
+ # There may be junk add the end of the file
+ # See http://stackoverflow.com/q/4928560/35070 for details
+ for i in range(1, 1024):
+ try:
+ gz = gzip.GzipFile(fileobj=io.BytesIO(content[:-i]), mode='rb')
+ uncompressed = io.BytesIO(gz.read())
+ except IOError:
+ continue
+ break
+ else:
+ raise original_ioerror
+ resp = self.addinfourl_wrapper(uncompressed, old_resp.headers, old_resp.url, old_resp.code)
resp.msg = old_resp.msg
# deflate
if resp.headers.get('Content-encoding', '') == 'deflate':