superbrain-server 1.0.40 → 1.0.41

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.40",
3
+ "version": "1.0.41",
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,7 +141,7 @@ 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
+ if False: # Prevent using full file which causes 100% CPU lock on EC2 t2.micro
144
145
  # Try the original file first (no re-encoding overhead)
145
146
  result = await _shazam_recognize_file(shazam, audio_path)
146
147
  else:
package/payload/fix.py ADDED
@@ -0,0 +1,25 @@
1
+ import re
2
+
3
+ with open(r'd:\superbrain\backend\main.py', 'r', encoding='utf-8') as f:
4
+ code = f.read()
5
+
6
+ # Fix 1: _parse_field for TAGS was reading 📸 and no variable existed for tags init correctly in old code, wait, let's look at what was there.
7
+ code = code.replace(
8
+ 'summary = _parse_field(summary_text, "📸", "TAGS")',
9
+ 'summary = _parse_field(summary_text, "📸", "SUMMARY")\n raw_tags = _parse_field(summary_text, "🏷️", "TAGS")'
10
+ )
11
+
12
+ # Fix 2: inject music extraction
13
+ code = code.replace(
14
+ '# Category: grab first word/phrase',
15
+ '''music = _parse_field(summary_text, "🎵", "MUSIC")
16
+ if not music:
17
+ _mm = re.search(r'(?:^|\\n)\\s*\\*{0,2}MUSIC\\*{0,2}:?\\s*([^\\n]+)', summary_text, re.IGNORECASE)
18
+ if _mm:
19
+ music = _mm.group(1).strip()
20
+
21
+ # Category: grab first word/phrase'''
22
+ )
23
+
24
+ with open(r'd:\superbrain\backend\main.py', 'w', encoding='utf-8') as f:
25
+ f.write(code)
package/payload/main.py CHANGED
@@ -83,9 +83,12 @@ 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
+ if 'Song:' in output:
87
+ song_line = [line for line in output.split('\n') if 'Song:' in line][0]
88
+ artist_line = [line for line in output.split('\n') if 'Artist:' in line]
89
+
90
+ song = song_line.split('Song:')[1].strip()
91
+ artist = artist_line[0].split('Artist:')[1].strip() if artist_line else 'Unknown'
89
92
  music_info += f"- {song} by {artist}\n"
90
93
  elif 'No match found' in output:
91
94
  music_info += "- No music identified (likely voiceover/no background music)\n"
@@ -231,6 +234,12 @@ def parse_summary(summary_text):
231
234
  if raw_tags:
232
235
  tags = [t.strip() for t in re.split(r'[\s,]+', raw_tags) if t.strip()]
233
236
 
237
+ music = _parse_field(summary_text, "🎵", "MUSIC")
238
+ if not music:
239
+ _mm = re.search(r'(?:^|\n)\s*\*{0,2}MUSIC\*{0,2}:?\s*([^\n]+)', summary_text, re.IGNORECASE)
240
+ if _mm:
241
+ music = _mm.group(1).strip()
242
+
234
243
  # Category: grab first word/phrase that matches a known category
235
244
  raw_cat = _parse_field(summary_text, "📂", "CATEGORY").lower()
236
245
  # Strip markdown bold leftovers and pick first line
@@ -0,0 +1,28 @@
1
+ import asyncio
2
+ import os
3
+ from instagram.instagram_downloader import download_instagram_content
4
+ from analyzers.music_identifier import identify_music
5
+
6
+ async def test():
7
+ print('Downloading...')
8
+ try:
9
+ url = 'https://www.instagram.com/reel/DWGy0xKk0DV/?igsh=bDJ5ZHozOHh6dHFr'
10
+ folder = download_instagram_content(url)
11
+ print('Downloaded to:', folder)
12
+ # Find the .mp3 file in the folder
13
+ audio_path = None
14
+ for root, dirs, files in os.walk(folder):
15
+ for file in files:
16
+ if file.endswith('.mp3'):
17
+ audio_path = os.path.join(root, file)
18
+ break
19
+ print('Identifying music on:', audio_path)
20
+ music_res = await identify_music(audio_path)
21
+ print('Music Result:', music_res)
22
+ except Exception as e:
23
+ print('Error:', e)
24
+ import traceback
25
+ traceback.print_exc()
26
+
27
+ if __name__ == '__main__':
28
+ asyncio.run(test())