Update where downloads go

This commit is contained in:
Grant Sanderson
2024-12-05 15:27:57 -06:00
parent c96734ace0
commit 75527563de
3 changed files with 8 additions and 6 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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)