NagisaNao commited on
Commit
b875b4d
·
verified ·
1 Parent(s): 12ae06e

update download code 2

Browse files
files_cells/notebooks/en/downloading_en.ipynb CHANGED
@@ -186,10 +186,6 @@
186
  " ## Update extensions\n",
187
  " if latest_exstensions:\n",
188
  " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
189
- "\n",
190
- " # # My Chinese friend, you broke the images again in the latest update... >W<'\n",
191
- " # %cd {webui_path}/extensions/Encrypt-Image\n",
192
- " # !git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3\n",
193
  " del cap\n",
194
  " print(f\"\\r✨ {action} Completed!\")\n",
195
  "\n",
@@ -362,16 +358,15 @@
362
  " print(f\"An error occurred: {e}\")\n",
363
  " return None\n",
364
  "\n",
365
- "def extract_file_and_image_info(data):\n",
366
  " model_name = data['files'][0]['name'] # get original model file name\n",
367
  " image_url = data['images'][0]['url'] # get preview: first image\n",
368
  " return model_name, image_url\n",
369
  "\n",
370
- "def generate_preview_filename(model_name, image_url):\n",
371
  " name = model_name.split('.')\n",
372
- " img_ext = image_url.split('.')\n",
373
- " print(f\"\\n\\033[31m[Preview DL]\\033[0m: {name[0]}.preview.{img_ext[-1]}\")\n",
374
- " return f\"{name[0]}.preview.{img_ext[-1]}\" # assigning the original image format\n",
375
  "\n",
376
  "''' main download code '''\n",
377
  "\n",
@@ -395,27 +390,33 @@
395
  " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
396
  " aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
397
  "\n",
398
- " print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
399
- " # print(url, dst_dir, file_name)\n",
400
- "\n",
401
  " # === CivitAi API ===\n",
402
  " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
403
  " if 'civitai' in url:\n",
 
404
  " model_id = url.split('/')[-1]\n",
405
- " url = f\"{url}&token={civitai_token}\" if '?' in url else f\"{url}?token={civitai_token}\"\n",
406
  "\n",
407
- " if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter\n",
408
  " data = get_data_from_api(model_id, civitai_token)\n",
409
  " if data:\n",
410
- " model_name, image_url = extract_file_and_image_info(data)\n",
411
  " if model_name and image_url:\n",
412
- " image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)\n",
413
  " with capture.capture_output() as cap: # clear shit\n",
414
  " !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
415
  " del cap\n",
 
 
416
  " else:\n",
417
  " print(\"\\033[31m[Preview DL]\\033[0m: Failed to retrieve data from the API.\")\n",
418
  "\n",
 
 
 
 
 
 
419
  " # -- GDrive --\n",
420
  " if 'drive.google' in url:\n",
421
  " try:\n",
@@ -532,7 +533,6 @@
532
  " urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
533
  " for url in urls:\n",
534
  " if url.startswith(\"http\") and url not in unique_urls:\n",
535
- " # handle_manual(f\"{current_tag}:{url}\")\n",
536
  " files_urls += f\"{current_tag}:{url}, \"\n",
537
  " unique_urls.append(url)\n",
538
  "\n",
 
186
  " ## Update extensions\n",
187
  " if latest_exstensions:\n",
188
  " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
 
 
 
 
189
  " del cap\n",
190
  " print(f\"\\r✨ {action} Completed!\")\n",
191
  "\n",
 
358
  " print(f\"An error occurred: {e}\")\n",
359
  " return None\n",
360
  "\n",
361
+ "def extract_model_info(data):\n",
362
  " model_name = data['files'][0]['name'] # get original model file name\n",
363
  " image_url = data['images'][0]['url'] # get preview: first image\n",
364
  " return model_name, image_url\n",
365
  "\n",
366
+ "def gen_preview_filename(model_name, image_url):\n",
367
  " name = model_name.split('.')\n",
368
+ " img_exts = image_url.split('.')\n",
369
+ " return f\"{name[0]}.preview.{img_exts[-1]}\" # assigning the original image format\n",
 
370
  "\n",
371
  "''' main download code '''\n",
372
  "\n",
 
390
  " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
391
  " aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
392
  "\n",
 
 
 
393
  " # === CivitAi API ===\n",
394
  " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
395
  " if 'civitai' in url:\n",
396
+ " image_file_name = None\n",
397
  " model_id = url.split('/')[-1]\n",
398
+ " url = f\"{url}&token={civitai_token}\" if '?' in url else f\"{url}?token={civitai_token}\" # some authors are pussies and they need API token...\n",
399
  "\n",
400
+ " if dst_dir in [models_dir, embeddings_dir, loras_dir]: # filter\n",
401
  " data = get_data_from_api(model_id, civitai_token)\n",
402
  " if data:\n",
403
+ " model_name, image_url = extract_model_info(data)\n",
404
  " if model_name and image_url:\n",
405
+ " image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)\n",
406
  " with capture.capture_output() as cap: # clear shit\n",
407
  " !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
408
  " del cap\n",
409
+ " if not file_name:\n",
410
+ " file_name = model_name\n",
411
  " else:\n",
412
  " print(\"\\033[31m[Preview DL]\\033[0m: Failed to retrieve data from the API.\")\n",
413
  "\n",
414
+ "\n",
415
+ " # print(url, dst_dir, file_name if not 'huggingface' in url else basename) # for my tests\n",
416
+ " print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name if not 'huggingface' in url else basename}\\033[0m\")\n",
417
+ " print(f\"\\033[31m[Preview DL]\\033[0m: {image_file_name}\") if 'civitai' in url and image_file_name else None # CivitiAi PreviewDl\n",
418
+ "\n",
419
+ "\n",
420
  " # -- GDrive --\n",
421
  " if 'drive.google' in url:\n",
422
  " try:\n",
 
533
  " urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
534
  " for url in urls:\n",
535
  " if url.startswith(\"http\") and url not in unique_urls:\n",
 
536
  " files_urls += f\"{current_tag}:{url}, \"\n",
537
  " unique_urls.append(url)\n",
538
  "\n",
files_cells/notebooks/ru/downloading_ru.ipynb CHANGED
@@ -186,10 +186,6 @@
186
  " ## Update extensions\n",
187
  " if latest_exstensions:\n",
188
  " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
189
- "\n",
190
- " # # My Chinese friend, you broke the images again in the latest update... >W<'\n",
191
- " # %cd {webui_path}/extensions/Encrypt-Image\n",
192
- " # !git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3\n",
193
  " del cap\n",
194
  " print(f\"\\r✨ {action} Завершено!\")\n",
195
  "\n",
@@ -362,16 +358,15 @@
362
  " print(f\"An error occurred: {e}\")\n",
363
  " return None\n",
364
  "\n",
365
- "def extract_file_and_image_info(data):\n",
366
  " model_name = data['files'][0]['name'] # get original model file name\n",
367
  " image_url = data['images'][0]['url'] # get preview: first image\n",
368
  " return model_name, image_url\n",
369
  "\n",
370
- "def generate_preview_filename(model_name, image_url):\n",
371
  " name = model_name.split('.')\n",
372
- " img_ext = image_url.split('.')\n",
373
- " print(f\"\\n\\033[31m[Preview DL]\\033[0m: {name[0]}.preview.{img_ext[-1]}\")\n",
374
- " return f\"{name[0]}.preview.{img_ext[-1]}\" # assigning the original image format\n",
375
  "\n",
376
  "''' main download code '''\n",
377
  "\n",
@@ -395,27 +390,33 @@
395
  " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
396
  " aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
397
  "\n",
398
- " print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
399
- " # print(url, dst_dir, file_name)\n",
400
- "\n",
401
  " # === CivitAi API ===\n",
402
  " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
403
  " if 'civitai' in url:\n",
 
404
  " model_id = url.split('/')[-1]\n",
405
- " url = f\"{url}&token={civitai_token}\" if '?' in url else f\"{url}?token={civitai_token}\"\n",
406
  "\n",
407
- " if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter\n",
408
  " data = get_data_from_api(model_id, civitai_token)\n",
409
  " if data:\n",
410
- " model_name, image_url = extract_file_and_image_info(data)\n",
411
  " if model_name and image_url:\n",
412
- " image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)\n",
413
  " with capture.capture_output() as cap: # clear shit\n",
414
  " !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
415
  " del cap\n",
 
 
416
  " else:\n",
417
  " print(\"\\033[31m[Preview DL]\\033[0m: Failed to retrieve data from the API.\")\n",
418
  "\n",
 
 
 
 
 
 
419
  " # -- GDrive --\n",
420
  " if 'drive.google' in url:\n",
421
  " try:\n",
@@ -532,7 +533,6 @@
532
  " urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
533
  " for url in urls:\n",
534
  " if url.startswith(\"http\") and url not in unique_urls:\n",
535
- " # handle_manual(f\"{current_tag}:{url}\")\n",
536
  " files_urls += f\"{current_tag}:{url}, \"\n",
537
  " unique_urls.append(url)\n",
538
  "\n",
 
186
  " ## Update extensions\n",
187
  " if latest_exstensions:\n",
188
  " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
 
 
 
 
189
  " del cap\n",
190
  " print(f\"\\r✨ {action} Завершено!\")\n",
191
  "\n",
 
358
  " print(f\"An error occurred: {e}\")\n",
359
  " return None\n",
360
  "\n",
361
+ "def extract_model_info(data):\n",
362
  " model_name = data['files'][0]['name'] # get original model file name\n",
363
  " image_url = data['images'][0]['url'] # get preview: first image\n",
364
  " return model_name, image_url\n",
365
  "\n",
366
+ "def gen_preview_filename(model_name, image_url):\n",
367
  " name = model_name.split('.')\n",
368
+ " img_exts = image_url.split('.')\n",
369
+ " return f\"{name[0]}.preview.{img_exts[-1]}\" # assigning the original image format\n",
 
370
  "\n",
371
  "''' main download code '''\n",
372
  "\n",
 
390
  " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
391
  " aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
392
  "\n",
 
 
 
393
  " # === CivitAi API ===\n",
394
  " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
395
  " if 'civitai' in url:\n",
396
+ " image_file_name = None\n",
397
  " model_id = url.split('/')[-1]\n",
398
+ " url = f\"{url}&token={civitai_token}\" if '?' in url else f\"{url}?token={civitai_token}\" # some authors are pussies and they need API token...\n",
399
  "\n",
400
+ " if dst_dir in [models_dir, embeddings_dir, loras_dir]: # filter\n",
401
  " data = get_data_from_api(model_id, civitai_token)\n",
402
  " if data:\n",
403
+ " model_name, image_url = extract_model_info(data)\n",
404
  " if model_name and image_url:\n",
405
+ " image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)\n",
406
  " with capture.capture_output() as cap: # clear shit\n",
407
  " !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
408
  " del cap\n",
409
+ " if not file_name:\n",
410
+ " file_name = model_name\n",
411
  " else:\n",
412
  " print(\"\\033[31m[Preview DL]\\033[0m: Failed to retrieve data from the API.\")\n",
413
  "\n",
414
+ "\n",
415
+ " # print(url, dst_dir, file_name if not 'huggingface' in url else basename) # for my tests\n",
416
+ " print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name if not 'huggingface' in url else basename}\\033[0m\")\n",
417
+ " print(f\"\\033[31m[Preview DL]\\033[0m: {image_file_name}\") if 'civitai' in url and image_file_name else None # CivitiAi PreviewDl\n",
418
+ "\n",
419
+ "\n",
420
  " # -- GDrive --\n",
421
  " if 'drive.google' in url:\n",
422
  " try:\n",
 
533
  " urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
534
  " for url in urls:\n",
535
  " if url.startswith(\"http\") and url not in unique_urls:\n",
 
536
  " files_urls += f\"{current_tag}:{url}, \"\n",
537
  " unique_urls.append(url)\n",
538
  "\n",
files_cells/python/en/downloading_en.py CHANGED
@@ -167,10 +167,6 @@ if latest_webui or latest_exstensions:
167
  ## Update extensions
168
  if latest_exstensions:
169
  get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
170
-
171
- # # My Chinese friend, you broke the images again in the latest update... >W<'
172
- # %cd {webui_path}/extensions/Encrypt-Image
173
- # !git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3
174
  del cap
175
  print(f"\r✨ {action} Completed!")
176
 
@@ -343,16 +339,15 @@ def get_data_from_api(model_id, api_key): # get model data
343
  print(f"An error occurred: {e}")
344
  return None
345
 
346
- def extract_file_and_image_info(data):
347
  model_name = data['files'][0]['name'] # get original model file name
348
  image_url = data['images'][0]['url'] # get preview: first image
349
  return model_name, image_url
350
 
351
- def generate_preview_filename(model_name, image_url):
352
  name = model_name.split('.')
353
- img_ext = image_url.split('.')
354
- print(f"\n\033[31m[Preview DL]\033[0m: {name[0]}.preview.{img_ext[-1]}")
355
- return f"{name[0]}.preview.{img_ext[-1]}" # assigning the original image format
356
 
357
  ''' main download code '''
358
 
@@ -376,27 +371,33 @@ def manual_download(url, dst_dir, file_name):
376
  basename = url.split("/")[-1] if file_name is None else file_name
377
  aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
378
 
379
- print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[0m")
380
- # print(url, dst_dir, file_name)
381
-
382
  # === CivitAi API ===
383
  civitai_token = "62c0c5956b2f9defbd844d754000180b"
384
  if 'civitai' in url:
 
385
  model_id = url.split('/')[-1]
386
- url = f"{url}&token={civitai_token}" if '?' in url else f"{url}?token={civitai_token}"
387
 
388
- if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter
389
  data = get_data_from_api(model_id, civitai_token)
390
  if data:
391
- model_name, image_url = extract_file_and_image_info(data)
392
  if model_name and image_url:
393
- image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)
394
  with capture.capture_output() as cap: # clear shit
395
  get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
396
  del cap
 
 
397
  else:
398
  print("\033[31m[Preview DL]\033[0m: Failed to retrieve data from the API.")
399
 
 
 
 
 
 
 
400
  # -- GDrive --
401
  if 'drive.google' in url:
402
  try:
@@ -513,7 +514,6 @@ def process_file_download(file_url):
513
  urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
514
  for url in urls:
515
  if url.startswith("http") and url not in unique_urls:
516
- # handle_manual(f"{current_tag}:{url}")
517
  files_urls += f"{current_tag}:{url}, "
518
  unique_urls.append(url)
519
 
 
167
  ## Update extensions
168
  if latest_exstensions:
169
  get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
 
 
 
 
170
  del cap
171
  print(f"\r✨ {action} Completed!")
172
 
 
339
  print(f"An error occurred: {e}")
340
  return None
341
 
342
+ def extract_model_info(data):
343
  model_name = data['files'][0]['name'] # get original model file name
344
  image_url = data['images'][0]['url'] # get preview: first image
345
  return model_name, image_url
346
 
347
+ def gen_preview_filename(model_name, image_url):
348
  name = model_name.split('.')
349
+ img_exts = image_url.split('.')
350
+ return f"{name[0]}.preview.{img_exts[-1]}" # assigning the original image format
 
351
 
352
  ''' main download code '''
353
 
 
371
  basename = url.split("/")[-1] if file_name is None else file_name
372
  aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
373
 
 
 
 
374
  # === CivitAi API ===
375
  civitai_token = "62c0c5956b2f9defbd844d754000180b"
376
  if 'civitai' in url:
377
+ image_file_name = None
378
  model_id = url.split('/')[-1]
379
+ url = f"{url}&token={civitai_token}" if '?' in url else f"{url}?token={civitai_token}" # some authors are pussies and they need API token...
380
 
381
+ if dst_dir in [models_dir, embeddings_dir, loras_dir]: # filter
382
  data = get_data_from_api(model_id, civitai_token)
383
  if data:
384
+ model_name, image_url = extract_model_info(data)
385
  if model_name and image_url:
386
+ image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)
387
  with capture.capture_output() as cap: # clear shit
388
  get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
389
  del cap
390
+ if not file_name:
391
+ file_name = model_name
392
  else:
393
  print("\033[31m[Preview DL]\033[0m: Failed to retrieve data from the API.")
394
 
395
+
396
+ # print(url, dst_dir, file_name if not 'huggingface' in url else basename) # for my tests
397
+ print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name if not 'huggingface' in url else basename}\033[0m")
398
+ print(f"\033[31m[Preview DL]\033[0m: {image_file_name}") if 'civitai' in url and image_file_name else None # CivitiAi PreviewDl
399
+
400
+
401
  # -- GDrive --
402
  if 'drive.google' in url:
403
  try:
 
514
  urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
515
  for url in urls:
516
  if url.startswith("http") and url not in unique_urls:
 
517
  files_urls += f"{current_tag}:{url}, "
518
  unique_urls.append(url)
519
 
files_cells/python/ru/downloading_ru.py CHANGED
@@ -167,10 +167,6 @@ if latest_webui or latest_exstensions:
167
  ## Update extensions
168
  if latest_exstensions:
169
  get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
170
-
171
- # # My Chinese friend, you broke the images again in the latest update... >W<'
172
- # %cd {webui_path}/extensions/Encrypt-Image
173
- # !git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3
174
  del cap
175
  print(f"\r✨ {action} Завершено!")
176
 
@@ -343,16 +339,15 @@ def get_data_from_api(model_id, api_key): # get model data
343
  print(f"An error occurred: {e}")
344
  return None
345
 
346
- def extract_file_and_image_info(data):
347
  model_name = data['files'][0]['name'] # get original model file name
348
  image_url = data['images'][0]['url'] # get preview: first image
349
  return model_name, image_url
350
 
351
- def generate_preview_filename(model_name, image_url):
352
  name = model_name.split('.')
353
- img_ext = image_url.split('.')
354
- print(f"\n\033[31m[Preview DL]\033[0m: {name[0]}.preview.{img_ext[-1]}")
355
- return f"{name[0]}.preview.{img_ext[-1]}" # assigning the original image format
356
 
357
  ''' main download code '''
358
 
@@ -376,27 +371,33 @@ def manual_download(url, dst_dir, file_name):
376
  basename = url.split("/")[-1] if file_name is None else file_name
377
  aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
378
 
379
- print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[0m")
380
- # print(url, dst_dir, file_name)
381
-
382
  # === CivitAi API ===
383
  civitai_token = "62c0c5956b2f9defbd844d754000180b"
384
  if 'civitai' in url:
 
385
  model_id = url.split('/')[-1]
386
- url = f"{url}&token={civitai_token}" if '?' in url else f"{url}?token={civitai_token}"
387
 
388
- if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter
389
  data = get_data_from_api(model_id, civitai_token)
390
  if data:
391
- model_name, image_url = extract_file_and_image_info(data)
392
  if model_name and image_url:
393
- image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)
394
  with capture.capture_output() as cap: # clear shit
395
  get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
396
  del cap
 
 
397
  else:
398
  print("\033[31m[Preview DL]\033[0m: Failed to retrieve data from the API.")
399
 
 
 
 
 
 
 
400
  # -- GDrive --
401
  if 'drive.google' in url:
402
  try:
@@ -513,7 +514,6 @@ def process_file_download(file_url):
513
  urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
514
  for url in urls:
515
  if url.startswith("http") and url not in unique_urls:
516
- # handle_manual(f"{current_tag}:{url}")
517
  files_urls += f"{current_tag}:{url}, "
518
  unique_urls.append(url)
519
 
 
167
  ## Update extensions
168
  if latest_exstensions:
169
  get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
 
 
 
 
170
  del cap
171
  print(f"\r✨ {action} Завершено!")
172
 
 
339
  print(f"An error occurred: {e}")
340
  return None
341
 
342
+ def extract_model_info(data):
343
  model_name = data['files'][0]['name'] # get original model file name
344
  image_url = data['images'][0]['url'] # get preview: first image
345
  return model_name, image_url
346
 
347
+ def gen_preview_filename(model_name, image_url):
348
  name = model_name.split('.')
349
+ img_exts = image_url.split('.')
350
+ return f"{name[0]}.preview.{img_exts[-1]}" # assigning the original image format
 
351
 
352
  ''' main download code '''
353
 
 
371
  basename = url.split("/")[-1] if file_name is None else file_name
372
  aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
373
 
 
 
 
374
  # === CivitAi API ===
375
  civitai_token = "62c0c5956b2f9defbd844d754000180b"
376
  if 'civitai' in url:
377
+ image_file_name = None
378
  model_id = url.split('/')[-1]
379
+ url = f"{url}&token={civitai_token}" if '?' in url else f"{url}?token={civitai_token}" # some authors are pussies and they need API token...
380
 
381
+ if dst_dir in [models_dir, embeddings_dir, loras_dir]: # filter
382
  data = get_data_from_api(model_id, civitai_token)
383
  if data:
384
+ model_name, image_url = extract_model_info(data)
385
  if model_name and image_url:
386
+ image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)
387
  with capture.capture_output() as cap: # clear shit
388
  get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
389
  del cap
390
+ if not file_name:
391
+ file_name = model_name
392
  else:
393
  print("\033[31m[Preview DL]\033[0m: Failed to retrieve data from the API.")
394
 
395
+
396
+ # print(url, dst_dir, file_name if not 'huggingface' in url else basename) # for my tests
397
+ print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name if not 'huggingface' in url else basename}\033[0m")
398
+ print(f"\033[31m[Preview DL]\033[0m: {image_file_name}") if 'civitai' in url and image_file_name else None # CivitiAi PreviewDl
399
+
400
+
401
  # -- GDrive --
402
  if 'drive.google' in url:
403
  try:
 
514
  urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
515
  for url in urls:
516
  if url.startswith("http") and url not in unique_urls:
 
517
  files_urls += f"{current_tag}:{url}, "
518
  unique_urls.append(url)
519