Skip to content

Commit

Permalink
download: download only once
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Oct 25, 2023
1 parent 83edce2 commit 41332fd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions happypose/toolbox/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def main():
)
)

print(f"{to_dl=}")
# logger.info(f"{to_dl=}")
asyncio.run(adownloads(*to_dl))


Expand Down Expand Up @@ -380,6 +380,16 @@ async def download_dir(self, download_path, local_path, flags):
)

async def download_file(self, download_path, local_path):
local_path = Path(local_path)
if local_path.exists():
# logger.info(f"Existing {download_path=}")
local_size = local_path.stat().st_size
head = await self.client.head(download_path)
if "content-length" in head.headers and local_size == int(
head.headers["content-length"]
):
logger.info(f"Skipping {download_path} already fully downloaded")
return
try:
r = await self.client.get(download_path)
except httpx.PoolTimeout:
Expand All @@ -389,8 +399,8 @@ async def download_file(self, download_path, local_path):
logger.error(f"Failed {download_path} with code {r.status_code}")
return
logger.info(f"Copying {download_path} to {local_path}")
Path(local_path.parent).mkdir(parents=True, exist_ok=True)
with open(str(local_path), "wb") as f:
local_path.parent.mkdir(parents=True, exist_ok=True)
with local_path.open("wb") as f:
f.write(r.content)


Expand Down

0 comments on commit 41332fd

Please sign in to comment.