mirror of
https://github.com/3b1b/manim.git
synced 2025-07-29 04:53:34 +08:00
Update where downloads go
This commit is contained in:
@ -10,7 +10,7 @@ directories:
|
|||||||
vector_images: ""
|
vector_images: ""
|
||||||
# If you want to use sounds, manim will look here to find it.
|
# If you want to use sounds, manim will look here to find it.
|
||||||
sounds: ""
|
sounds: ""
|
||||||
temporary_storage: ""
|
downloads: ""
|
||||||
# For certain object types, especially Tex and Text, manim will save information
|
# 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,
|
# 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,
|
# it stores this saved data to whatever directory appdirs.user_cache_dir("manim") returns,
|
||||||
|
@ -23,7 +23,7 @@ def get_temp_dir() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def get_downloads_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:
|
def get_output_dir() -> str:
|
||||||
|
@ -6,6 +6,10 @@ import hashlib
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import validators
|
import validators
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
import manimlib.utils.directories
|
||||||
|
from manimlib.utils.simple_functions import hash_string
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
@ -35,11 +39,9 @@ def find_file(
|
|||||||
# Check if this is a file online first, and if so, download
|
# Check if this is a file online first, and if so, download
|
||||||
# it to a temporary directory
|
# it to a temporary directory
|
||||||
if validators.url(file_name):
|
if validators.url(file_name):
|
||||||
import urllib.request
|
|
||||||
from manimlib.utils.directories import get_downloads_dir
|
|
||||||
suffix = Path(file_name).suffix
|
suffix = Path(file_name).suffix
|
||||||
file_hash = hashlib.sha256(file_name.encode('utf-8')).hexdigest()[:32]
|
file_hash = hash_string(file_name)
|
||||||
folder = get_downloads_dir()
|
folder = manimlib.utils.directories.get_downloads_dir()
|
||||||
|
|
||||||
path = Path(folder, file_hash).with_suffix(suffix)
|
path = Path(folder, file_hash).with_suffix(suffix)
|
||||||
urllib.request.urlretrieve(file_name, path)
|
urllib.request.urlretrieve(file_name, path)
|
||||||
|
Reference in New Issue
Block a user