Factor Studios commited on
Commit
ca2d4cf
·
verified ·
1 Parent(s): 924af9d

Update vision_analyzer.py

Browse files
Files changed (1) hide show
  1. vision_analyzer.py +14 -14
vision_analyzer.py CHANGED
@@ -170,39 +170,39 @@ def log_message(message: str):
170
  if len(processing_status["logs"]) > 100:
171
  processing_status["logs"] = processing_status["logs"][-100:]
172
 
173
- import libarchive.public
 
 
174
 
175
  def extract_with_retry(rar_path: str, output_dir: str, max_retries: int = 2) -> bool:
176
- """Extract RAR file using libarchive with retry logic"""
177
  filename = os.path.basename(rar_path)
178
 
179
- # Handle multipart RAR detection but don't remap paths (libarchive usually handles it if complete)
180
  if is_multipart_rar(filename):
181
  base_name = get_rar_part_base(filename)
182
  first_part = f"{base_name}.part01.rar"
183
  first_part_path = os.path.join(os.path.dirname(rar_path), first_part)
 
184
  if not os.path.exists(first_part_path):
185
  log_message(f"⚠️ Multi-part RAR detected but first part not found: {first_part}")
186
  return False
 
187
  rar_path = first_part_path
188
  log_message(f"📦 Processing multi-part RAR starting with: {first_part}")
189
 
190
  for attempt in range(max_retries):
191
  try:
192
- with libarchive.public.file_reader(rar_path) as archive:
193
- for entry in archive:
194
- out_path = os.path.join(output_dir, entry.pathname)
195
- os.makedirs(os.path.dirname(out_path), exist_ok=True)
196
- with open(out_path, "wb") as f:
197
- for block in entry.get_blocks():
198
- f.write(block)
199
- log_message(f"✅ Successfully extracted: {os.path.basename(rar_path)}")
200
  return True
 
 
 
201
  except Exception as e:
202
- log_message(f"⚠️ libarchive extraction attempt {attempt + 1} failed: {str(e)}")
203
  time.sleep(1)
204
-
205
- log_message(f"❌ Failed to extract: {os.path.basename(rar_path)}")
206
  return False
207
 
208
 
 
170
  if len(processing_status["logs"]) > 100:
171
  processing_status["logs"] = processing_status["logs"][-100:]
172
 
173
+
174
+ import patoolib
175
+ from patoolib.util import PatoolError
176
 
177
  def extract_with_retry(rar_path: str, output_dir: str, max_retries: int = 2) -> bool:
178
+ """Extract RAR or ZIP file using patoolib with retry logic"""
179
  filename = os.path.basename(rar_path)
180
 
181
+ # Handle multi-part RARs (skip them if patoolib can't handle)
182
  if is_multipart_rar(filename):
183
  base_name = get_rar_part_base(filename)
184
  first_part = f"{base_name}.part01.rar"
185
  first_part_path = os.path.join(os.path.dirname(rar_path), first_part)
186
+
187
  if not os.path.exists(first_part_path):
188
  log_message(f"⚠️ Multi-part RAR detected but first part not found: {first_part}")
189
  return False
190
+
191
  rar_path = first_part_path
192
  log_message(f"📦 Processing multi-part RAR starting with: {first_part}")
193
 
194
  for attempt in range(max_retries):
195
  try:
196
+ os.makedirs(output_dir, exist_ok=True)
197
+ patoolib.extract_archive(rar_path, outdir=output_dir, verbosity=-1)
198
+ log_message(f"✅ Successfully extracted: {filename} using patoolib")
 
 
 
 
 
199
  return True
200
+ except PatoolError as e:
201
+ log_message(f"⚠️ patoolib extraction attempt {attempt + 1} failed: {str(e)}")
202
+ time.sleep(1)
203
  except Exception as e:
204
+ log_message(f" patoolib exception: {str(e)}")
205
  time.sleep(1)
 
 
206
  return False
207
 
208