implemented stream

This commit is contained in:
Hellow2
2023-03-31 09:47:03 +02:00
parent 5067b84f48
commit c93c469576
6 changed files with 51 additions and 18 deletions

View File

@@ -140,6 +140,9 @@ class ID3Timestamp:
minute=minute,
second=second
)
def __hash__(self):
return self.date_obj.__hash__()
def __lt__(self, other):
return self.date_obj < other.date_obj

View File

@@ -1,6 +1,8 @@
from typing import Optional, List, Tuple
from pathlib import Path
from collections import defaultdict
import requests
# from tqdm import tqdm
from ..utils import shared
from .parents import DatabaseObject
@@ -60,3 +62,26 @@ class Target(DatabaseObject):
copy_to.create_path()
with open(self.file_path, "wb") as write_to:
write_to.write(read_from.read())
def stream_into(self, r: requests.Response):
self.create_path()
chunk_size = 1024
total_size = int(r.headers.get('content-length'))
initial_pos = 0
with open(self.file_path,'wb') as f:
for chunk in r.iter_content(chunk_size=chunk_size):
size = f.write(chunk)
"""
# doesn't work yet due to
# https://github.com/tqdm/tqdm/issues/261
with open(self.file_path,'wb') as f, \
tqdm(desc=self._file, total=total_size, unit='iB', unit_scale=True, unit_divisor=chunk_size) as pbar:
for chunk in r.iter_content(chunk_size=chunk_size):
size = f.write(chunk)
pbar.update(size)
"""