diff --git a/manimlib/default_config.yml b/manimlib/default_config.yml index 211ec110..3e38d24a 100644 --- a/manimlib/default_config.yml +++ b/manimlib/default_config.yml @@ -10,7 +10,7 @@ directories: vector_images: "" # If you want to use sounds, manim will look here to find it. sounds: "" - temporary_storage: "" + downloads: "" # For certain object types, especially Tex and Text, manim will save information # to file to prevent the need to re-compute, e.g. recompiling the latex. By default, # it stores this saved data to whatever directory appdirs.user_cache_dir("manim") returns, diff --git a/manimlib/utils/directories.py b/manimlib/utils/directories.py index e4a5358d..e4a2bc03 100644 --- a/manimlib/utils/directories.py +++ b/manimlib/utils/directories.py @@ -23,7 +23,7 @@ def get_temp_dir() -> str: def get_downloads_dir() -> str: - return guarantee_existence(os.path.join(get_temp_dir(), "manim_downloads")) + return get_directories()["downloads"] or appdirs.user_cache_dir("manim_downloads") def get_output_dir() -> str: diff --git a/manimlib/utils/file_ops.py b/manimlib/utils/file_ops.py index 0e436b68..26faa449 100644 --- a/manimlib/utils/file_ops.py +++ b/manimlib/utils/file_ops.py @@ -6,6 +6,10 @@ import hashlib import numpy as np import validators +import urllib.request + +import manimlib.utils.directories +from manimlib.utils.simple_functions import hash_string from typing import TYPE_CHECKING @@ -35,11 +39,9 @@ def find_file( # Check if this is a file online first, and if so, download # it to a temporary directory if validators.url(file_name): - import urllib.request - from manimlib.utils.directories import get_downloads_dir suffix = Path(file_name).suffix - file_hash = hashlib.sha256(file_name.encode('utf-8')).hexdigest()[:32] - folder = get_downloads_dir() + file_hash = hash_string(file_name) + folder = manimlib.utils.directories.get_downloads_dir() path = Path(folder, file_hash).with_suffix(suffix) urllib.request.urlretrieve(file_name, path)