mirror of
https://github.com/ihabunek/twitch-dl
synced 2024-08-30 18:32:25 +00:00
Improve naming
This commit is contained in:
parent
1658aba124
commit
5679e66270
@ -11,29 +11,29 @@ CONNECT_TIMEOUT = 5
|
|||||||
RETRY_COUNT = 5
|
RETRY_COUNT = 5
|
||||||
|
|
||||||
|
|
||||||
def _download(url: str, path: Path):
|
def _download(url: str, target: Path):
|
||||||
tmp_path = Path(str(path) + ".tmp")
|
tmp_path = Path(str(target) + ".tmp")
|
||||||
size = 0
|
size = 0
|
||||||
with httpx.stream("GET", url, timeout=CONNECT_TIMEOUT, follow_redirects=True) as response:
|
with httpx.stream("GET", url, timeout=CONNECT_TIMEOUT, follow_redirects=True) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
with open(tmp_path, "wb") as target:
|
with open(tmp_path, "wb") as f:
|
||||||
for chunk in response.iter_bytes(chunk_size=CHUNK_SIZE):
|
for chunk in response.iter_bytes(chunk_size=CHUNK_SIZE):
|
||||||
target.write(chunk)
|
f.write(chunk)
|
||||||
size += len(chunk)
|
size += len(chunk)
|
||||||
|
|
||||||
os.rename(tmp_path, path)
|
os.rename(tmp_path, target)
|
||||||
return size
|
return size
|
||||||
|
|
||||||
|
|
||||||
def download_file(url: str, path: Path, retries: int = RETRY_COUNT) -> Tuple[int, bool]:
|
def download_file(url: str, target: Path, retries: int = RETRY_COUNT) -> Tuple[int, bool]:
|
||||||
if path.exists():
|
if target.exists():
|
||||||
from_disk = True
|
from_disk = True
|
||||||
return os.path.getsize(path), from_disk
|
return os.path.getsize(target), from_disk
|
||||||
|
|
||||||
from_disk = False
|
from_disk = False
|
||||||
for _ in range(retries):
|
for _ in range(retries):
|
||||||
try:
|
try:
|
||||||
return _download(url, path), from_disk
|
return _download(url, target), from_disk
|
||||||
except httpx.RequestError:
|
except httpx.RequestError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user