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

Update vision_analyzer.py

Browse files
Files changed (1) hide show
  1. vision_analyzer.py +26 -9
vision_analyzer.py CHANGED
@@ -170,26 +170,43 @@ def log_message(message: str):
170
  if len(processing_status["logs"]) > 100:
171
  processing_status["logs"] = processing_status["logs"][-100:]
172
 
 
 
173
  def extract_with_retry(rar_path: str, output_dir: str, max_retries: int = 2) -> bool:
174
- """Extract RAR file using rarfile module with retry logic"""
175
- from rarfile import RarFile, BadRarFile
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  for attempt in range(max_retries):
178
  try:
179
- with RarFile(rar_path) as rf:
180
- rf.extractall(path=output_dir)
 
 
 
 
 
181
  log_message(f"✅ Successfully extracted: {os.path.basename(rar_path)}")
182
  return True
183
- except BadRarFile as brf:
184
- log_message(f"❌ Bad RAR file: {brf}")
185
- return False
186
  except Exception as e:
187
- log_message(f"⚠️ Extraction attempt {attempt + 1} failed: {str(e)}")
188
  time.sleep(1)
189
-
 
190
  return False
191
 
192
 
 
193
  def log_failed_file(filename: str, error: str):
194
  """Log failed files to persistent file"""
195
  with open(FAILED_FILES_LOG, "a") as f:
 
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
 
209
+
210
  def log_failed_file(filename: str, error: str):
211
  """Log failed files to persistent file"""
212
  with open(FAILED_FILES_LOG, "a") as f: