From d5df7460dcbf5dcef8c2fb6b11df934a347e02f6 Mon Sep 17 00:00:00 2001 From: tehkillerbee Date: Mon, 14 Oct 2024 21:46:52 +0200 Subject: [PATCH] Fix: Logical loop of is_encrypted / encryption_key. --- HISTORY.rst | 2 ++ examples/pkce_example.py | 21 +++++++++++++-------- tidalapi/media.py | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ed42822..308875a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,7 @@ History ======= v0.7.7 ------ +* Bugfix: Logical loop of is_encrypted / encryption_key - TooYoungTooSimp_ * Tests: Added additional playlist, folder tests. - tehkillerbee_ * Feature: Add support for playlist merging. - tehkillerbee_ * Added trn to playlist object for convenience. - tehkillerbee_ @@ -215,6 +216,7 @@ v0.6.2 .. _quodrum-glas: https://github.com/quodrum-glas .. _M4TH1EU: https://github.com/M4TH1EU .. _GioF71: https://github.com/GioF71 +.. _TooYoungTooSimp: https://github.com/TooYoungTooSimp diff --git a/examples/pkce_example.py b/examples/pkce_example.py index 451a691..d6f2a8d 100644 --- a/examples/pkce_example.py +++ b/examples/pkce_example.py @@ -17,9 +17,10 @@ # """pkce_example.py: A simple example script that describes how to use PKCE login and MPEG-DASH streams""" +from pathlib import Path + import tidalapi from tidalapi import Quality -from pathlib import Path session_file1 = Path("tidal-session-pkce.json") @@ -51,12 +52,16 @@ manifest = stream.get_stream_manifest() audio_resolution = stream.get_audio_resolution() - print("track:{}, (quality:{}, codec:{}, {}bit/{}Hz)".format(track.id, - stream.audio_quality, - manifest.get_codecs(), - audio_resolution[0], - audio_resolution[1])) - if stream.is_MPD: + print( + "track:{}, (quality:{}, codec:{}, {}bit/{}Hz)".format( + track.id, + stream.audio_quality, + manifest.get_codecs(), + audio_resolution[0], + audio_resolution[1], + ) + ) + if stream.is_mpd: # HI_RES_LOSSLESS quality supported when using MPEG-DASH stream (PKCE only!) # 1. Export as MPD manifest mpd = stream.get_manifest_data() @@ -66,7 +71,7 @@ # my_file.write(mpd) # with open("{}_{}.m3u8".format(album_id, track.id), "w") as my_file: # my_file.write(hls) - elif stream.is_BTS: + elif stream.is_bts: # Direct URL (m4a or flac) is available for Quality < HI_RES_LOSSLESS url = manifest.get_urls() break diff --git a/tidalapi/media.py b/tidalapi/media.py index 8b42c82..461cd8b 100644 --- a/tidalapi/media.py +++ b/tidalapi/media.py @@ -617,7 +617,7 @@ def __init__(self, stream: Stream): self.mime_type = stream_manifest["mimeType"] self.encryption_type = stream_manifest["encryptionType"] self.encryption_key = ( - stream_manifest["encryptionKey"] if self.is_encrypted else None + stream_manifest.get("keyId") if self.encryption_type else None ) else: raise UnknownManifestFormat