From 44d1f0d7db4b463bb385355dd229b099279c6213 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Thu, 11 Apr 2024 20:13:12 +0200 Subject: [PATCH] fix: musify downloading --- music_kraken/connection/connection.py | 10 +++++++--- music_kraken/pages/musify.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/music_kraken/connection/connection.py b/music_kraken/connection/connection.py index 41b5c07..eb3de20 100644 --- a/music_kraken/connection/connection.py +++ b/music_kraken/connection/connection.py @@ -119,7 +119,7 @@ class Connection: ) -> Dict[str, str]: headers = self.get_header(**(headers or {})) if not refer_from_origin: - headers["Referer"] = self.base_url(url=url) + headers["Referer"] = self.base_url(url=url) return headers @@ -145,6 +145,7 @@ class Connection: disable_cache: bool = None, method: str = None, name: str = "", + exclude_headers: List[str] = None, **kwargs ) -> Optional[requests.Response]: if method is None: @@ -158,7 +159,6 @@ class Connection: current_kwargs.pop("kwargs") current_kwargs.update(**kwargs) - parsed_url = urlparse(url) if not raw_headers: @@ -195,6 +195,10 @@ class Connection: if timeout is None: timeout = self.TIMEOUT + for header in exclude_headers or []: + if header in headers: + del headers[header] + r = None connection_failed = False try: @@ -308,7 +312,7 @@ class Connection: return DownloadResult(error_message=f"Could not establish a stream from: {url}") target.create_path() - total_size = int(r.headers.get('content-length')) + total_size = int(r.headers.get('content-length', r.headers.get('Content-Length', chunk_size))) progress = 0 retry = False diff --git a/music_kraken/pages/musify.py b/music_kraken/pages/musify.py index 371633a..90912bf 100644 --- a/music_kraken/pages/musify.py +++ b/music_kraken/pages/musify.py @@ -118,7 +118,13 @@ class Musify(Page): def __init__(self, *args, **kwargs): self.connection: Connection = Connection( host="https://musify.club/", - logger=self.LOGGER + logger=self.LOGGER, + ) + + self.stream_connection: Connection = Connection( + host="https://musify.club/", + logger=self.LOGGER, + semantic_not_found=False, ) super().__init__(*args, **kwargs) @@ -1121,4 +1127,4 @@ class Musify(Page): self.LOGGER.warning(f"The source has no audio link. Falling back to {endpoint}.") - return self.connection.stream_into(endpoint, target, raw_url=True) + return self.stream_connection.stream_into(endpoint, target, raw_url=True, exclude_headers=["Host"])