From 0b9baa86009a8ea0b1368a30573b2c85fa48f412 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sat, 10 Feb 2024 17:31:30 +0100 Subject: [PATCH] Update function name and add batched & awaited dls --- src/edl.gd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/edl.gd b/src/edl.gd index 86c735b..1b9338a 100644 --- a/src/edl.gd +++ b/src/edl.gd @@ -32,7 +32,7 @@ func generate_id() -> int: logger.diag("Generated new download id " + str(id)) return id -func await_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary: +func awaited_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary: logger.verb("Creating awaited download") var id: int = create_download(url, method, headers, data) start_download(id) @@ -42,6 +42,18 @@ func await_download(url: String, method: HTTPClient.Method = HTTPClient.Method.M list_complete.erase(id) return dldata +func batch_awaited_download(urls: PackedStringArray, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]: + logger.verb("Creating " + str(urls.size()) + " awaited download(s)") + var dldata: Array[Dictionary] + for url in urls: + var id: int = create_download(url, method, headers, data) + start_download(id) + logger.diag("Waiting for download " + str(id) + " to finish") + while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout + dldata.append(list_complete[id]) + list_complete.erase(id) + return dldata + func create_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), body: String = "") -> int: logger.verb("Creating new download\n-> URL: " + url + "\n-> Method: " + str(method) + "\nHeaders:\n" + str(headers) + "\nBody:\n" + body) var id = generate_id()