Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'blenderkit/download.py')
-rw-r--r--blenderkit/download.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/blenderkit/download.py b/blenderkit/download.py
index c4a14ecd..c9df6c0b 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -523,6 +523,34 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff, not
return .5
+def download_file(asset_data):
+ #this is a simple non-threaded way to download files for background resolution genenration tool
+ file_name = paths.get_download_filenames(asset_data)[0] # prefer global dir if possible.
+
+ if check_existing(asset_data):
+ # this sends the thread for processing, where another check should occur, since the file might be corrupted.
+ utils.p('not downloading, already in db')
+ return file_name
+ preferences = bpy.context.preferences.addons['blenderkit'].preferences
+ api_key = preferences.api_key
+
+ with open(file_name, "wb") as f:
+ print("Downloading %s" % file_name)
+ headers = utils.get_headers(api_key)
+
+ response = requests.get(asset_data['url'], stream=True)
+ total_length = response.headers.get('Content-Length')
+
+ if total_length is None: # no content length header
+ f.write(response.content)
+ else:
+ dl = 0
+ for data in response.iter_content(chunk_size=4096):
+ dl += len(data)
+ print(dl)
+ f.write(data)
+ return file_name
+
class Downloader(threading.Thread):
def __init__(self, asset_data, tcom, scene_id, api_key):
super(Downloader, self).__init__()