diff --git a/src/actual_donwload.py b/src/actual_donwload.py index d952d59..ccb7610 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -5,48 +5,10 @@ print("Setting logging-level to DEBUG") logging.getLogger().setLevel(logging.DEBUG) if __name__ == "__main__": - normally_download = [ - "s: #a Favorite #r Anarcho", - "1", - "d: 1, 5" - ] - - direct_download = [ - "d: https://musify.club/release/crystal-f-x-2012-795181" - ] - - fetch_musify_song = [ - "s: https://musify.club/track/blokkmonsta-schwartz-crystal-f-purer-hass-8369115" - ] - - fetch_youtube_playlist = [ - "s: https://yt.artemislena.eu/playlist?list=OLAK5uy_kcUBiDv5ATbl-R20OjNaZ5G28XFanQOmM" - ] - - download_youtube_playlist = ["d: https://www.youtube.com/playlist?list=OLAK5uy_lqI_c6aDF9q4DWJ4TBzt1AFQYx_FXfU4E"] - - youtube_search = [ - "s: #a Zombiez", - "10", - "d: 5" - ] - - youtube_music_test = [ - "s: #a Only Smile #r Your best friend", - "8", - "2", - "d: 2" - ] - - cross_download = [ - "s: #a Psychonaut 4", - "2", - "d: 0" - ] - commands = [ "s: #a PTK", - "d: 26", + "26", + "d: 1", ] diff --git a/src/music_kraken/connection/cache.py b/src/music_kraken/connection/cache.py index eaeee9d..4bc2b2b 100644 --- a/src/music_kraken/connection/cache.py +++ b/src/music_kraken/connection/cache.py @@ -24,8 +24,7 @@ class CacheAttribute: @property def is_valid(self): if isinstance(self.expires, str): - pass - # self.expires = datetime.fromisoformat(self.expires) + self.expires = datetime.fromisoformat(self.expires) return datetime.now() < self.expires def __eq__(self, other): diff --git a/src/music_kraken/connection/connection.py b/src/music_kraken/connection/connection.py index b723e0a..ce98326 100644 --- a/src/music_kraken/connection/connection.py +++ b/src/music_kraken/connection/connection.py @@ -38,13 +38,11 @@ class Connection: ): if proxies is None: proxies = main_settings["proxies"] - if header_values is None: - header_values = dict() self.cache: Cache = Cache(module=module, logger=logger) self.cache_expiring_duration = cache_expiring_duration - self.HEADER_VALUES = header_values + self.HEADER_VALUES = dict() if header_values is None else header_values self.LOGGER = logger self.HOST = urlparse(host) @@ -151,10 +149,16 @@ class Connection: accepted_response_codes = self.ACCEPTED_RESPONSE_CODES if accepted_response_codes is None else accepted_response_codes current_kwargs = copy.copy(locals()) + current_kwargs.pop("kwargs") + current_kwargs.update(**kwargs) + parsed_url = urlparse(url) + _headers = copy.copy(self.HEADER_VALUES) + _headers.update(headers) + headers = self._update_headers( - headers=headers, + headers=_headers, refer_from_origin=refer_from_origin, url=parsed_url ) @@ -318,6 +322,6 @@ class Connection: if retry: self.LOGGER.warning(f"Retrying stream...") accepted_response_codes.add(206) - return self.stream_into(**stream_kwargs) + return Connection.stream_into(**stream_kwargs) return DownloadResult() diff --git a/src/music_kraken/pages/youtube_music/youtube_music.py b/src/music_kraken/pages/youtube_music/youtube_music.py index f126a95..cf0bd0d 100644 --- a/src/music_kraken/pages/youtube_music/youtube_music.py +++ b/src/music_kraken/pages/youtube_music/youtube_music.py @@ -189,7 +189,11 @@ class YoutubeMusic(SuperYouTube): self.download_connection: Connection = Connection( host="https://rr2---sn-cxaf0x-nugl.googlevideo.com/", logger=self.LOGGER, - sleep_after_404=youtube_settings["sleep_after_youtube_403"] + sleep_after_404=youtube_settings["sleep_after_youtube_403"], + header_values={ + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8", + "Referer": "https://music.youtube.com/", + } ) # https://github.com/ytdl-org/youtube-dl/blob/master/README.md#embedding-youtube-dl @@ -507,8 +511,7 @@ class YoutubeMusic(SuperYouTube): return song def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult: - if source.audio_url is None: - self.fetch_song(source) + self.fetch_song(source) if source.audio_url is None: self.LOGGER.warning(f"Couldn't fetch the audio source with the innertube api, falling back to invidious.")