superbrain-server 1.0.40 → 1.0.42
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
|
@@ -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
|
|
112
|
-
|
|
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
|
|
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/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 '
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
@@ -817,6 +826,30 @@ def main():
|
|
|
817
826
|
# Extract structured data from summary for database
|
|
818
827
|
title, summary_text, tags, music, category = parse_summary(final_summary)
|
|
819
828
|
|
|
829
|
+
# OVERRIDE LLM MUSIC WITH DIRECT SHAZAM OUTPUT TO PRESERVE LINKS
|
|
830
|
+
if results.get('music_identification'):
|
|
831
|
+
for item in results['music_identification']:
|
|
832
|
+
out = item['output']
|
|
833
|
+
if 'Song:' in out:
|
|
834
|
+
song = [l.split('Song:')[1].strip() for l in out.split('\n') if 'Song:' in l][0]
|
|
835
|
+
artist_line = [l.split('Artist:')[1].strip() for l in out.split('\n') if 'Artist:' in l]
|
|
836
|
+
artist = artist_line[0] if artist_line else 'Unknown'
|
|
837
|
+
link = ""
|
|
838
|
+
spot_line = [l.split('Spotify:')[1].strip() for l in out.split('\n') if 'Spotify:' in l]
|
|
839
|
+
apple_line = [l.split('Apple Music:')[1].strip() for l in out.split('\n') if 'Apple Music:' in l]
|
|
840
|
+
if spot_line:
|
|
841
|
+
link = spot_line[0]
|
|
842
|
+
elif apple_line:
|
|
843
|
+
link = apple_line[0]
|
|
844
|
+
music = f"{song} by {artist}"
|
|
845
|
+
if link:
|
|
846
|
+
music += f" | {link}"
|
|
847
|
+
break
|
|
848
|
+
elif 'No match found' in out:
|
|
849
|
+
music = "No music identified"
|
|
850
|
+
break
|
|
851
|
+
|
|
852
|
+
|
|
820
853
|
# Get additional metadata from info.txt if available
|
|
821
854
|
username = ""
|
|
822
855
|
likes = 0
|