implemented mutiple download feature.

This commit is contained in:
2023-05-09 14:38:13 +09:00
parent c724af538b
commit e7197673fc
3 changed files with 72 additions and 17 deletions

View File

@ -80,3 +80,17 @@ class FileApi(BaseApi):
response = self._get(url)
self._raise_response_error(response)
return response.json()
def download(self, file: File, path: str) -> bool:
print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
url = self.connection.build_url("v2/", file.download_url)
r = self.connection.session.get(url, stream=True)
try:
with open(path, "wb") as f:
for chunk in r.iter_content(chunk_size=4096):
if chunk:
f.write(chunk)
f.flush()
except PermissionError:
print(f"Cannot create file `{path}`: Permission denied.")
return True