adbrasi commited on
Commit
8e7014d
verified
1 Parent(s): f8f4e07

Update wanForProduction.sh

Browse files
Files changed (1) hide show
  1. wanForProduction.sh +41 -5
wanForProduction.sh CHANGED
@@ -143,6 +143,8 @@ download_hf() {
143
  temp_dir="$(mktemp -d)"
144
  success=false
145
 
 
 
146
  if command -v hf >/dev/null 2>&1; then
147
  local hf_cmd=(hf download "$repo_id" "$file_path")
148
  if [[ -n "$revision" ]]; then
@@ -160,6 +162,7 @@ download_hf() {
160
  if [[ "$success" == false ]]; then
161
  local fallback_revision="${revision:-main}"
162
  local direct_url="https://huggingface.co/${repo_id}/resolve/${fallback_revision}/${file_path}"
 
163
  if command -v aria2c >/dev/null 2>&1; then
164
  local aria_cmd=(aria2c -c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10 --dir "$temp_dir" --out "$filename")
165
  if [[ -n "$HF_TOKEN" ]]; then
@@ -219,6 +222,7 @@ download_hf() {
219
  return 1
220
  }
221
 
 
222
  download_file() {
223
  local url="$1"
224
  local target_dir="$2"
@@ -250,6 +254,7 @@ download_file() {
250
  local attempt success
251
  for attempt in 1 2 3; do
252
  success=false
 
253
  if command -v aria2c >/dev/null 2>&1; then
254
  if aria2c -c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10 --dir "$target_dir" --out "$final_name" "$url"; then
255
  success=true
@@ -295,18 +300,49 @@ download_mega() {
295
 
296
  local attempt
297
  for attempt in 1 2 3; do
298
- if (cd "$target_dir" && megadl "$url"); then
299
- log_success "Download Mega.nz conclu铆do"
300
- return 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  fi
302
- log_warn "Tentativa $attempt falhou para Mega.nz"
303
- sleep $((2 * attempt))
304
  done
305
 
306
  log_error "Falha ao baixar de Mega.nz: $url"
307
  return 1
308
  }
309
 
 
 
310
  process_downloads() {
311
  local failed=0
312
  for entry in "${DOWNLOAD_FILES[@]}"; do
 
143
  temp_dir="$(mktemp -d)"
144
  success=false
145
 
146
+ log_info "[HF] Tentativa $attempt/3: ${repo_id}/${file_path}${revision:+ @}${revision:+$revision}"
147
+
148
  if command -v hf >/dev/null 2>&1; then
149
  local hf_cmd=(hf download "$repo_id" "$file_path")
150
  if [[ -n "$revision" ]]; then
 
162
  if [[ "$success" == false ]]; then
163
  local fallback_revision="${revision:-main}"
164
  local direct_url="https://huggingface.co/${repo_id}/resolve/${fallback_revision}/${file_path}"
165
+ log_warn "[HF] Tentativa $attempt usando fallback HTTP"
166
  if command -v aria2c >/dev/null 2>&1; then
167
  local aria_cmd=(aria2c -c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10 --dir "$temp_dir" --out "$filename")
168
  if [[ -n "$HF_TOKEN" ]]; then
 
222
  return 1
223
  }
224
 
225
+
226
  download_file() {
227
  local url="$1"
228
  local target_dir="$2"
 
254
  local attempt success
255
  for attempt in 1 2 3; do
256
  success=false
257
+ log_info "[DL] Tentativa $attempt/3: ${final_name}"
258
  if command -v aria2c >/dev/null 2>&1; then
259
  if aria2c -c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10 --dir "$target_dir" --out "$final_name" "$url"; then
260
  success=true
 
300
 
301
  local attempt
302
  for attempt in 1 2 3; do
303
+ log_info "[MEGA] Tentativa $attempt/3"
304
+ local temp_dir
305
+ temp_dir="$(mktemp -d)"
306
+ if megadl --path "$temp_dir" "$url"; then
307
+ local moved=0
308
+ while IFS= read -r -d '' file; do
309
+ if [[ ! -f "$file" ]]; then
310
+ continue
311
+ fi
312
+ local base
313
+ base="$(basename "$file")"
314
+ if [[ -f "$target_dir/$base" ]]; then
315
+ log_success "J谩 existe: $base"
316
+ else
317
+ if mv "$file" "$target_dir/$base"; then
318
+ log_success "Download Mega.nz conclu铆do: $base"
319
+ else
320
+ log_warn "Falha ao mover $base para destino final"
321
+ continue
322
+ fi
323
+ fi
324
+ moved=1
325
+ done < <(find "$temp_dir" -type f -print0)
326
+
327
+ rm -rf "$temp_dir"
328
+ if (( moved )); then
329
+ return 0
330
+ fi
331
+ log_warn "[MEGA] Nenhum arquivo detectado ap贸s download"
332
+ sleep $((2 * attempt))
333
+ else
334
+ log_warn "Tentativa $attempt falhou para Mega.nz"
335
+ rm -rf "$temp_dir"
336
+ sleep $((2 * attempt))
337
  fi
 
 
338
  done
339
 
340
  log_error "Falha ao baixar de Mega.nz: $url"
341
  return 1
342
  }
343
 
344
+
345
+
346
  process_downloads() {
347
  local failed=0
348
  for entry in "${DOWNLOAD_FILES[@]}"; do