From eb27511031859f5d24800df1f71079e880c4f8aa Mon Sep 17 00:00:00 2001 From: nathom Date: Fri, 14 May 2021 22:46:07 -0700 Subject: [PATCH] Make pycryptodome an optional dependency #79 --- streamrip/utils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/streamrip/utils.py b/streamrip/utils.py index 6bb3676..4843343 100644 --- a/streamrip/utils.py +++ b/streamrip/utils.py @@ -1,24 +1,19 @@ """Miscellaneous utility functions.""" import base64 -import contextlib import logging import os import re -import sys from string import Formatter from typing import Dict, Hashable, Optional, Union import click import requests -from Crypto.Cipher import AES -from Crypto.Util import Counter from pathvalidate import sanitize_filename from requests.packages import urllib3 from tqdm import tqdm -from tqdm.contrib import DummyTqdmFile -from .constants import AGENT, LOG_DIR, TIDAL_COVER_URL +from .constants import AGENT, TIDAL_COVER_URL from .exceptions import InvalidSourceError, NonStreamable urllib3.disable_warnings() @@ -215,6 +210,19 @@ def decrypt_mqa_file(in_path, out_path, encryption_key): :param out_path: :param encryption_key: """ + try: + from Crypto.Cipher import AES + from Crypto.Util import Counter + except (ImportError, ModuleNotFoundError): + click.secho( + "To download this item in MQA, you need to run ", + fg="yellow", + nl=False, + ) + click.secho("pip3 install pycryptodome --upgrade", fg="blue", nl=False) + click.secho(".") + raise click.Abort + # Do not change this master_key = "UIlTTEMmmLfGowo/UC60x2H45W6MdGgTRfo/umg4754="