From c52e487c42ca2acef291c4f32e3544746fef5ee7 Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Wed, 1 May 2024 10:36:47 -0700 Subject: [PATCH] Fix LSP errors --- streamrip/client/downloadable.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/streamrip/client/downloadable.py b/streamrip/client/downloadable.py index 2685a1b..7cf994e 100644 --- a/streamrip/client/downloadable.py +++ b/streamrip/client/downloadable.py @@ -42,8 +42,8 @@ class Downloadable(ABC): session: aiohttp.ClientSession url: str extension: str - chunk_size = 2**17 - _size: Optional[int] = None + chunk_size: int = 2**17 + _size_base: Optional[int] = None async def download(self, path: str, callback: Callable[[int], Any]): await self._download(path, callback) @@ -58,6 +58,14 @@ class Downloadable(ABC): self._size = int(content_length) return self._size + @property + def _size(self): + return self._size_base + + @_size.setter + def _size(self, v): + self._size_base = v + @abstractmethod async def _download(self, path: str, callback: Callable[[int], None]): raise NotImplementedError @@ -77,8 +85,13 @@ class BasicDownloadable(Downloadable): # yielding to event loop selector counter = 0 yield_every = 16 - with open(path, "wb") as file: - with requests.get(self.url, allow_redirects=True, stream=True) as resp: + with open(path, "wb") as file: # noqa: ASYNC101 + with requests.get( # noqa: ASYNC100 + self.url, + headers=self.session.headers, + allow_redirects=True, + stream=True, + ) as resp: for chunk in resp.iter_content(chunk_size=self.chunk_size): file.write(chunk) callback(len(chunk)) @@ -89,7 +102,6 @@ class BasicDownloadable(Downloadable): class DeezerDownloadable(Downloadable): is_encrypted = re.compile("/m(?:obile|edia)/") - # chunk_size = 2048 * 3 def __init__(self, session: aiohttp.ClientSession, info: dict): logger.debug("Deezer info for downloadable: %s", info)