superbrain-server 1.0.38 → 1.0.39

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.38",
3
+ "version": "1.0.39",
4
4
  "description": "1-Line Auto-Installer and Server Execution wrapper for SuperBrain",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -108,12 +108,13 @@ def _segment_positions(duration: float) -> list[float]:
108
108
 
109
109
  async def _shazam_recognize_file(shazam, path: str) -> dict | None:
110
110
  try:
111
- # t2.micro instances easily take 30+ seconds to generate audio fingerprints
112
- result = await asyncio.wait_for(shazam.recognize(path), timeout=60.0)
111
+ # t2.micro intances do heavy FFT math in python, which can take ~1.5 seconds per 1 second of audio.
112
+ # A 20s slice takes ~30-40s on standard micro instance caps.
113
+ result = await asyncio.wait_for(shazam.recognize(path), timeout=120.0)
113
114
  if result and "track" in result:
114
115
  return result
115
116
  except asyncio.TimeoutError:
116
- print("(shazam request timeout)")
117
+ print("(shazam request timeout 120s)")
117
118
  except Exception as e:
118
119
  print(f"(shazam error: {e})")
119
120
  return None
@@ -140,21 +141,22 @@ async def _shazam_multi_segment(audio_path: str) -> dict | None:
140
141
  label = f"@{int(start)}s" if start > 0 else "start"
141
142
  print(f" [Shazam] {i}/{total} {label}...", end=" ", flush=True)
142
143
 
143
- if start == 0:
144
- # Try the original file first (no re-encoding overhead)
145
- result = await _shazam_recognize_file(shazam, audio_path)
146
- else:
147
- seg = _extract_segment(audio_path, start, duration=12)
148
- if not seg:
149
- print("(extract failed)")
150
- continue
144
+ # NEVER pass the raw original file to Shazam on AWS t2.micro, because
145
+ # shazamio does a pure-Python FFT over the ENTIRE file length before sending!
146
+ # A 60 second file's FFT will easily hit a 60-second timeout on a micro vCPU.
147
+ # We MUST slice it to a tiny segment first using ffmpeg.
148
+ seg = _extract_segment(audio_path, start, duration=12)
149
+ if not seg:
150
+ print("(extract failed)")
151
+ continue
152
+
153
+ try:
154
+ result = await _shazam_recognize_file(shazam, seg)
155
+ finally:
151
156
  try:
152
- result = await _shazam_recognize_file(shazam, seg)
153
- finally:
154
- try:
155
- os.remove(seg)
156
- except Exception:
157
- pass
157
+ os.remove(seg)
158
+ except Exception:
159
+ pass
158
160
 
159
161
  if result:
160
162
  print("match!")
package/payload/main.py CHANGED
@@ -83,9 +83,13 @@ def generate_final_summary(results, instagram_url):
83
83
  music_info = "MUSIC:\n"
84
84
  for item in results['music_identification']:
85
85
  output = item['output']
86
- if '🎵 Song:' in output:
87
- song = output.split('🎵 Song:')[1].split('\n')[0].strip()
88
- artist = output.split('👤 Artist:')[1].split('\n')[0].strip() if '👤 Artist:' in output else 'Unknown'
86
+ # Accommodate potential emoji stripping in basic linux terminals
87
+ if 'Song:' in output:
88
+ song_line = [line for line in output.split('\n') if 'Song:' in line][0]
89
+ artist_line = [line for line in output.split('\n') if 'Artist:' in line]
90
+
91
+ song = song_line.split('Song:')[1].strip()
92
+ artist = artist_line[0].split('Artist:')[1].strip() if artist_line else 'Unknown'
89
93
  music_info += f"- {song} by {artist}\n"
90
94
  elif 'No match found' in output:
91
95
  music_info += "- No music identified (likely voiceover/no background music)\n"