superbrain-server 1.0.31 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superbrain-server",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "1-Line Auto-Installer and Server Execution wrapper for SuperBrain",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -58,20 +58,25 @@ def _extract_segment(audio_path: str, start_sec: float,
58
58
  try:
59
59
  fd, seg_path = tempfile.mkstemp(suffix=".mp3")
60
60
  os.close(fd)
61
- subprocess.run(
61
+ proc = subprocess.run(
62
62
  ["ffmpeg", "-y",
63
63
  "-ss", str(int(start_sec)),
64
64
  "-t", str(int(duration)),
65
65
  "-i", audio_path,
66
66
  "-acodec", "libmp3lame", "-q:a", "3",
67
67
  seg_path],
68
- capture_output=True, timeout=30,
68
+ capture_output=True, text=True, timeout=60,
69
69
  )
70
+
70
71
  if os.path.getsize(seg_path) > 1024:
71
72
  return seg_path
73
+ else:
74
+ print(f"(ffmpeg extracted <1024 bytes! stderr: {proc.stderr[:200]})")
75
+
72
76
  os.remove(seg_path)
73
77
  return None
74
- except Exception:
78
+ except Exception as e:
79
+ print(f"(ffmpeg failed: {e})")
75
80
  return None
76
81
 
77
82
 
@@ -103,11 +108,13 @@ def _segment_positions(duration: float) -> list[float]:
103
108
 
104
109
  async def _shazam_recognize_file(shazam, path: str) -> dict | None:
105
110
  try:
106
- result = await shazam.recognize(path)
111
+ result = await asyncio.wait_for(shazam.recognize(path), timeout=25.0)
107
112
  if result and "track" in result:
108
113
  return result
109
- except Exception:
110
- pass
114
+ except asyncio.TimeoutError:
115
+ print("(shazam request timeout)")
116
+ except Exception as e:
117
+ print(f"(shazam error: {e})")
111
118
  return None
112
119
 
113
120
 
package/payload/api.py CHANGED
@@ -231,7 +231,14 @@ def queue_worker():
231
231
  _active_processes[shortcode] = process
232
232
 
233
233
  # Wait for completion
234
- process.wait()
234
+ try:
235
+ process.wait(timeout=600)
236
+ except subprocess.TimeoutExpired:
237
+ logger.error(f"❌ [{shortcode}] Process timed out after 10 minutes. Killing...")
238
+ process.kill()
239
+ process.wait()
240
+ db.remove_from_queue(shortcode)
241
+ continue
235
242
 
236
243
  with _active_processes_lock:
237
244
  _active_processes.pop(shortcode, None)
@@ -568,7 +575,26 @@ async def analyze_instagram(request: AnalyzeRequest, token: str = Depends(verify
568
575
  _active_processes.pop(shortcode, None)
569
576
  return proc.returncode, ''.join(lines), proc.stderr.read()
570
577
 
571
- returncode, stdout, stderr = await asyncio.to_thread(_run_subprocess)
578
+ try:
579
+ returncode, stdout, stderr = await asyncio.wait_for(
580
+ asyncio.to_thread(_run_subprocess),
581
+ timeout=600
582
+ )
583
+ except asyncio.TimeoutError:
584
+ logger.error(f"❌ [{shortcode}] Analysis reached 10-minute timeout. Forcing termination.")
585
+ with _active_processes_lock:
586
+ proc = _active_processes.pop(shortcode, None)
587
+ if proc:
588
+ try:
589
+ proc.kill()
590
+ proc.wait()
591
+ except Exception:
592
+ pass
593
+ db.remove_from_queue(shortcode)
594
+ raise HTTPException(
595
+ status_code=504,
596
+ detail="Analysis timed out. The process took longer than the 10-minute allowed maximum."
597
+ )
572
598
 
573
599
  if stderr.strip():
574
600
  # Log stderr from main.py to help diagnose issues
@@ -1317,7 +1343,18 @@ async def export_data(
1317
1343
 
1318
1344
  async def download_image(client, sem, post_dict):
1319
1345
  url = post_dict.get('thumbnail_url') or post_dict.get('thumbnail')
1320
- if not url or url.startswith("/static/"):
1346
+ if not url:
1347
+ return None
1348
+
1349
+ if url.startswith("/static/"):
1350
+ local_path = url.replace("/static/", "", 1)
1351
+ full_path = _STATIC_DIR / local_path
1352
+ try:
1353
+ if full_path.exists():
1354
+ with open(full_path, "rb") as f:
1355
+ return (local_path, f.read())
1356
+ except Exception as e:
1357
+ logger.error(f"Failed bundling local image {url}: {e}")
1321
1358
  return None
1322
1359
 
1323
1360
  shortcode = post_dict.get('shortcode')
@@ -0,0 +1,5 @@
1
+ This movie 🍿🪄
2
+ .
3
+ .
4
+ .
5
+ #sunset #earth
@@ -0,0 +1,11 @@
1
+ A estrada dourada pelo pôr do sol, o vento no rosto e a mente em silêncio — terapia sobre duas rodas. 🏍❤️
2
+ .
3
+ .
4
+ .
5
+ .
6
+ .
7
+ .
8
+ .
9
+ .
10
+ .
11
+ #paz #moto #motociclismo
@@ -1,3 +0,0 @@
1
- Make sure you live….
2
-
3
- #reels #reelsfeelit #reelsinsta #ınstagmood #livelife