aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2009-12-21 21:43:15 +0100
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>2010-10-31 11:24:56 +0100
commit9c457d2a2019f3d52aa17614cc8087989e105413 (patch)
treedb5b47db712db049df19766a9d76e25d15cfde57
parentc39c05cdd7a0868ca94f10bc4a5157863dc53449 (diff)
Handle file open mode correctly (fixes issue #76)
-rwxr-xr-xyoutube-dl12
1 files changed, 9 insertions, 3 deletions
diff --git a/youtube-dl b/youtube-dl
index ea6245e9d..5f2381448 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -392,19 +392,21 @@ class FileDownloader(object):
def _do_download(self, filename, url):
stream = None
- open_mode = 'ab'
-
+ open_mode = 'wb'
basic_request = urllib2.Request(url, None, std_headers)
request = urllib2.Request(url, None, std_headers)
- # Attempt to resume download with "continuedl" option
+ # Establish possible resume length
if os.path.isfile(filename):
resume_len = os.path.getsize(filename)
else:
resume_len = 0
+
+ # Request parameters in case of being able to resume
if self.params.get('continuedl', False) and resume_len != 0:
self.report_resuming_byte(resume_len)
request.add_header('Range','bytes=%d-' % resume_len)
+ open_mode = 'ab'
# Establish connection
try:
@@ -412,12 +414,16 @@ class FileDownloader(object):
except (urllib2.HTTPError, ), err:
if err.code != 416: # 416 is 'Requested range not satisfiable'
raise
+ # Unable to resume
data = urllib2.urlopen(basic_request)
content_length = data.info()['Content-Length']
+
if content_length is not None and long(content_length) == resume_len:
+ # Because the file had already been fully downloaded
self.report_file_already_downloaded(filename)
return True
else:
+ # Because the server didn't let us
self.report_unable_to_resume()
open_mode = 'wb'