Spaces:
Sleeping
Sleeping
Update tabs/resources.py
Browse files- tabs/resources.py +18 -1
tabs/resources.py
CHANGED
@@ -158,12 +158,27 @@ def get_mediafire_download_link(url):
|
|
158 |
else:
|
159 |
return None
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
def download_from_url(url):
|
162 |
file_path = find_folder_parent(now_dir, "assets")
|
163 |
print(file_path)
|
164 |
zips_path = os.path.join(file_path, "assets", "zips")
|
165 |
print(zips_path)
|
166 |
os.makedirs(zips_path, exist_ok=True)
|
|
|
|
|
167 |
if url != "":
|
168 |
print(i18n("Downloading the file: ") + f"{url}")
|
169 |
if "drive.google.com" in url:
|
@@ -211,7 +226,7 @@ def download_from_url(url):
|
|
211 |
progress_percent = int((progress / total_size_in_bytes) * 100)
|
212 |
num_dots = int((progress / total_size_in_bytes) * progress_bar_length)
|
213 |
progress_bar = "[" + "." * num_dots + " " * (progress_bar_length - num_dots) + "]"
|
214 |
-
print(f"{progress_percent}% {progress_bar} {progress}/{total_size_in_bytes} ", end="\r")
|
215 |
if progress_percent == 100:
|
216 |
print("\n")
|
217 |
else:
|
@@ -337,6 +352,8 @@ def download_from_url(url):
|
|
337 |
realPath = os.path.join(currentPath, Files)
|
338 |
os.rename(realPath, nameFile + "." + extensionFile)
|
339 |
|
|
|
|
|
340 |
os.chdir(file_path)
|
341 |
print(i18n("Full download"))
|
342 |
return "downloaded"
|
|
|
158 |
else:
|
159 |
return None
|
160 |
|
161 |
+
def delete_large_files(directory_path, max_size_megabytes):
|
162 |
+
for filename in os.listdir(directory_path):
|
163 |
+
file_path = os.path.join(directory_path, filename)
|
164 |
+
if os.path.isfile(file_path):
|
165 |
+
size_in_bytes = os.path.getsize(file_path)
|
166 |
+
size_in_megabytes = size_in_bytes / (1024 * 1024) # Convert bytes to megabytes
|
167 |
+
|
168 |
+
if size_in_megabytes > max_size_megabytes:
|
169 |
+
print("###################################")
|
170 |
+
print(f"Deleting s*** {filename} (Size: {size_in_megabytes:.2f} MB)")
|
171 |
+
os.remove(file_path)
|
172 |
+
print("###################################")
|
173 |
+
|
174 |
def download_from_url(url):
|
175 |
file_path = find_folder_parent(now_dir, "assets")
|
176 |
print(file_path)
|
177 |
zips_path = os.path.join(file_path, "assets", "zips")
|
178 |
print(zips_path)
|
179 |
os.makedirs(zips_path, exist_ok=True)
|
180 |
+
print(f"Limit download size in MB {os.getenv('MAX_DOWNLOAD_SIZE')}, duplicate the space for modify the limit")
|
181 |
+
|
182 |
if url != "":
|
183 |
print(i18n("Downloading the file: ") + f"{url}")
|
184 |
if "drive.google.com" in url:
|
|
|
226 |
progress_percent = int((progress / total_size_in_bytes) * 100)
|
227 |
num_dots = int((progress / total_size_in_bytes) * progress_bar_length)
|
228 |
progress_bar = "[" + "." * num_dots + " " * (progress_bar_length - num_dots) + "]"
|
229 |
+
#print(f"{progress_percent}% {progress_bar} {progress}/{total_size_in_bytes} ", end="\r")
|
230 |
if progress_percent == 100:
|
231 |
print("\n")
|
232 |
else:
|
|
|
352 |
realPath = os.path.join(currentPath, Files)
|
353 |
os.rename(realPath, nameFile + "." + extensionFile)
|
354 |
|
355 |
+
delete_large_files(zips_path, int(os.getenv("MAX_DOWNLOAD_SIZE")))
|
356 |
+
|
357 |
os.chdir(file_path)
|
358 |
print(i18n("Full download"))
|
359 |
return "downloaded"
|