daasd commited on
Commit
d34e52d
·
1 Parent(s): 74aa496

Update main22.py

Browse files
Files changed (1) hide show
  1. main22.py +8 -5
main22.py CHANGED
@@ -227,6 +227,7 @@ def get_civitai_file(str):
227
  return match.group(0).split('\n')[0]
228
  else:
229
  print("无法从输出中提取文件名")
 
230
 
231
 
232
  def move_model(source_path, target_path):
@@ -243,17 +244,19 @@ def download_file(item):
243
  return
244
  download_url = item['downloadLink']
245
  # huggingface
246
- match = re.search(r'/([^/]*)$', download_url)
247
- file_name = match.group(1)
248
  # 开始下载
249
- if '.' not in match.group(1):
 
250
  if len(cookie)>0:
251
  cmd = ['aria2c', '--header', f'Cookie:{cookie}', '--console-log-level=error', '-c', '-x', '16', '-s', '16', '-k', '1M', download_url, '-d', lora_dir]
252
  else:
253
  cmd = f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M {download_url} -d {lora_dir}"
 
254
  else:
255
  cmd = f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M {download_url} -d {lora_dir} -o {file_name}"
256
- result = subprocess.run(cmd,stderr=subprocess.PIPE, stdout=subprocess.PIPE)
 
257
  if result.returncode == 0:
258
  # 判断是civitai还是hugging face还是自定义
259
  # civitai
@@ -297,7 +300,7 @@ def download_file(item):
297
  print(f"2.粘贴{item['downloadLink']}到链接输入栏进行跳转同时观察包含http s://civitai.com/api/download 的这个请求")
298
  print(f"3.将请求头的cookie复制下来在cookie的输入框中填入,重新执行2.2进行下载\n ")
299
  print("===============================================================================")
300
- print(f"{item['name']}下载失败,请检查{item['downloadLink']}")
301
  except Exception as e:
302
  traceback.print_exc()
303
 
 
227
  return match.group(0).split('\n')[0]
228
  else:
229
  print("无法从输出中提取文件名")
230
+ return ''
231
 
232
 
233
  def move_model(source_path, target_path):
 
244
  return
245
  download_url = item['downloadLink']
246
  # huggingface
247
+ file_name = urlparse(download_url).path.split("/")[-1]
 
248
  # 开始下载
249
+ if '.' not in file_name:
250
+ print("civitai")
251
  if len(cookie)>0:
252
  cmd = ['aria2c', '--header', f'Cookie:{cookie}', '--console-log-level=error', '-c', '-x', '16', '-s', '16', '-k', '1M', download_url, '-d', lora_dir]
253
  else:
254
  cmd = f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M {download_url} -d {lora_dir}"
255
+ result = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
256
  else:
257
  cmd = f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M {download_url} -d {lora_dir} -o {file_name}"
258
+ result = subprocess.run(cmd ,shell=True ,stderr=subprocess. PIPE, stdout=subprocess.PIPE)
259
+ print(result)
260
  if result.returncode == 0:
261
  # 判断是civitai还是hugging face还是自定义
262
  # civitai
 
300
  print(f"2.粘贴{item['downloadLink']}到链接输入栏进行跳转同时观察包含http s://civitai.com/api/download 的这个请求")
301
  print(f"3.将请求头的cookie复制下来在cookie的输入框中填入,重新执行2.2进行下载\n ")
302
  print("===============================================================================")
303
+ print(f"\033[91m{item['name']}下载失败,请检查{item['downloadLink']}\033[0m")
304
  except Exception as e:
305
  traceback.print_exc()
306