diff --git a/unshackle/core/drm/playready.py b/unshackle/core/drm/playready.py index 4b444a9..cbf4a96 100644 --- a/unshackle/core/drm/playready.py +++ b/unshackle/core/drm/playready.py @@ -421,7 +421,9 @@ class PlayReady: [binaries.ShakaPackager, *arguments], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, - universal_newlines=True, + text=True, + encoding="utf-8", + errors="replace", ) stream_skipped = False diff --git a/unshackle/core/utilities.py b/unshackle/core/utilities.py index 572ee4e..fad62d9 100644 --- a/unshackle/core/utilities.py +++ b/unshackle/core/utilities.py @@ -516,10 +516,10 @@ def try_ensure_utf8(data: bytes) -> bytes: # last ditch effort to detect encoding detection_result = chardet.detect(data) if not detection_result["encoding"]: - return data - return data.decode(detection_result["encoding"]).encode("utf8") - except UnicodeDecodeError: - return data + return data.decode("utf-8", errors="replace").encode("utf-8") + return data.decode(detection_result["encoding"], errors="replace").encode("utf8") + except (UnicodeDecodeError, LookupError): + return data.decode("utf-8", errors="replace").encode("utf-8") def get_free_port() -> int: