Skip to content

Commit

Permalink
resume downloads automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
jake authored and jake committed Aug 9, 2023
1 parent d7ecb73 commit 117f74a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internetarchive/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.6.0.dev1'
__version__ = '3.6.0.dev2'
11 changes: 9 additions & 2 deletions internetarchive/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def download(self, file_path=None, verbose=None, ignore_existing=None,
no_change_timestamp = no_change_timestamp or False
params = params or None
timeout = 12 if not timeout else timeout
headers = {}

self.item.session.mount_http_adapter(max_retries=retries)
file_path = file_path or self.name
Expand Down Expand Up @@ -244,6 +245,8 @@ def download(self, file_path=None, verbose=None, ignore_existing=None,
if verbose:
print(f' {msg}', file=sys.stderr)
return
else:
headers = {"Range": f"bytes={st.st_size}-{self.size}"}

parent_dir = os.path.dirname(file_path)
try:
Expand All @@ -254,7 +257,8 @@ def download(self, file_path=None, verbose=None, ignore_existing=None,
stream=True,
timeout=timeout,
auth=self.auth,
params=params)
params=params,
headers=headers)
response.raise_for_status()
if return_responses:
return response
Expand All @@ -274,7 +278,10 @@ def download(self, file_path=None, verbose=None, ignore_existing=None,
if stdout:
fileobj = os.fdopen(sys.stdout.fileno(), "wb", closefd=False)
if not fileobj:
fileobj = open(file_path.encode('utf-8'), 'wb')
if "Range" in headers:
fileobj = open(file_path.encode('utf-8'), 'ab')
else:
fileobj = open(file_path.encode('utf-8'), 'wb')

with fileobj, progress_bar as bar:
for chunk in response.iter_content(chunk_size=chunk_size):
Expand Down

0 comments on commit 117f74a

Please sign in to comment.