Skip to content

Commit

Permalink
[CI] Changed the name of the headers parameter to custom_headers and …
Browse files Browse the repository at this point in the history
…fixed some of its bugs
  • Loading branch information
henrique-coder committed Dec 18, 2024
1 parent 83d92f3 commit 0362d94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ downloader = Downloader(
connection_speed=80, # The connection speed in Mbps. (default: 80)
overwrite=True, # Overwrite the file if it already exists. Otherwise, a "_1", "_2", etc. suffix will be added. (default: True)
show_progress_bar=True, # Show or hide the download progress bar. (default: True)
headers=None, # Custom headers to include in the request. If None, default headers will be used. (default: None)
custom_headers=None, # Custom headers to include in the request. If None, default headers will be used. Imutable headers are 'Accept-Encoding' and 'Range'. (default: None)
timeout=None # Timeout in seconds for the download process. Or None for no timeout. (default: None)
)

Expand Down
16 changes: 8 additions & 8 deletions streamsnapper/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
connection_speed: float = 80,
overwrite: bool = True,
show_progress_bar: bool = True,
headers: Optional[Dict[str, str]] = None,
custom_headers: Optional[Dict[str, str]] = None,
timeout: Optional[int] = None,
) -> None:
"""
Expand All @@ -37,7 +37,7 @@ def __init__(
connection_speed: The connection speed in Mbps. (default: 80)
overwrite: Overwrite the file if it already exists. Otherwise, a "_1", "_2", etc. suffix will be added. (default: True)
show_progress_bar: Show or hide the download progress bar. (default: True)
headers: Custom headers to include in the request. If None, default headers will be used. (default: None)
custom_headers: Custom headers to include in the request. If None, default headers will be used. Imutable headers are 'Accept-Encoding' and 'Range'. (default: None)
timeout: Timeout in seconds for the download process. Or None for no timeout. (default: None)
"""

Expand All @@ -49,18 +49,18 @@ def __init__(

imutable_headers = ['Accept-Encoding', 'Range']

self.headers: Dict[str, str] = {
self._custom_headers: Dict[str, str] = {
'Accept': '*/*',
'Accept-Encoding': 'identity',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
}

if headers:
for key, value in headers.items():
if custom_headers:
for key, value in custom_headers.items():
if key.title() not in imutable_headers:
self.headers[key.title()] = value
self._custom_headers[key.title()] = value

self._client: Client = Client(headers=self.headers, follow_redirects=True, timeout=self._timeout)
self._client: Client = Client(headers=self._custom_headers, follow_redirects=True, timeout=self._timeout)

self.output_path: str = None

Expand Down Expand Up @@ -232,7 +232,7 @@ def _download_chunk(self, url: str, start: int, end: int, progress: Progress, ta
DownloadError: If an error occurs while downloading the chunk.
"""

headers = {**self.headers}
headers = {**self._custom_headers}

chunk_size = min(8192, end - start + 1)
buffer = bytearray()
Expand Down

0 comments on commit 0362d94

Please sign in to comment.