imran056 commited on
Commit
d39d19a
Β·
verified Β·
1 Parent(s): 92f26bc

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +121 -29
server.js CHANGED
@@ -1,6 +1,6 @@
1
  // ═══════════════════════════════════════════════════════════
2
- // COMPLETE UPDATED BACKEND SERVER - PART 1 OF 2
3
- // Fixed: Session ID issue in /mashup/create endpoint
4
  // ═══════════════════════════════════════════════════════════
5
 
6
  const express = require('express');
@@ -74,6 +74,7 @@ const INSTRUMENTS = {
74
  }
75
  };
76
 
 
77
  const EFFECTS = {
78
  lofi: {
79
  name: "LoFi Hip Hop",
@@ -82,6 +83,16 @@ const EFFECTS = {
82
  instrumentVolume: 0,
83
  instrumentMoods: ["chill", "sad_romantic", "ambient"]
84
  },
 
 
 
 
 
 
 
 
 
 
85
  slowed_reverb: {
86
  name: "Slowed + Reverb",
87
  description: "Simple & authentic - like YouTube/TikTok (clean vocals, no instruments)",
@@ -89,6 +100,7 @@ const EFFECTS = {
89
  instrumentVolume: 0,
90
  instrumentMoods: []
91
  },
 
92
  nightcore: {
93
  name: "Nightcore",
94
  description: "High energy with bright sparkling sounds (With Instruments)",
@@ -96,6 +108,7 @@ const EFFECTS = {
96
  instrumentVolume: 0.04,
97
  instrumentMoods: ["upbeat", "romantic"]
98
  },
 
99
  vaporwave: {
100
  name: "Vaporwave",
101
  description: "Retro nostalgic with dreamy sad vibes (With Instruments)",
@@ -103,6 +116,7 @@ const EFFECTS = {
103
  instrumentVolume: 0.005,
104
  instrumentMoods: ["sad_romantic", "ambient", "sad"]
105
  },
 
106
  "8d_audio": {
107
  name: "8D Audio",
108
  description: "Immersive 360Β° with ambient dreamy layers (With Instruments)",
@@ -110,13 +124,16 @@ const EFFECTS = {
110
  instrumentVolume: 0.05,
111
  instrumentMoods: ["ambient", "romantic", "sad_romantic"]
112
  },
 
 
113
  bass_boosted: {
114
  name: "Bass Boosted",
115
- description: "Heavy bass with deep atmospheric tones (With Instruments)",
116
- baseCommand: `bass=g=18:f=55:width_type=o:width=1.5,bass=g=14:f=95:width_type=h:width=90,equalizer=f=35:t=q:width=1.2:g=12,equalizer=f=75:t=q:width=1.5:g=10,equalizer=f=140:t=q:width=2:g=8,equalizer=f=500:t=q:width=2:g=-3,equalizer=f=4000:t=q:width=4:g=-6,acompressor=threshold=-22dB:ratio=8:attack=3:release=40:makeup=8,tremolo=f=0.15:d=0.3,highpass=f=28,alimiter=limit=0.95:attack=5:release=50,volume=1.5`,
117
  instrumentVolume: 0.05,
118
  instrumentMoods: ["ambient", "chill"]
119
  },
 
120
  ambient: {
121
  name: "Ambient Chill",
122
  description: "Ethereal meditation with sad peaceful vibes (With Instruments)",
@@ -469,35 +486,32 @@ async function matchTempo(inputPath, targetBPM, currentBPM, identifier) {
469
  return inputPath;
470
  }
471
  }
472
- // ═══════════════════════════════════════════════════════════
473
- // COMPLETE UPDATED BACKEND SERVER - PART 2 OF 2
474
- // Copy Part 1 + Part 2 together into one server.js file
475
- // ═══════════════════════════════════════════════════════════
476
 
477
  // API ENDPOINTS
478
 
479
  app.get('/', (req, res) => {
480
  res.json({
481
  status: 'online',
482
- message: '🎡 Unified Mashup API v14.0 - SIMPLE SLOWED+REVERB',
483
- version: '14.0',
484
  features: [
485
  '🎭 Smart Genre Detection (8 genres)',
486
  '🎬 CapCut-style Timeline Editor',
487
- '🎨 LoFi Effects (7 effects)',
488
  'πŸ”€ Natural Crossfade',
489
- '🎹 Smart Instrument Mixing (NOT in LoFi/Slowed+Reverb)',
490
  '🎡 BPM Detection & Tempo Matching',
491
  '🎯 Genre Compatibility Check',
492
  'πŸ“Š Frequency Spectrum Analysis',
493
  'βœ‚οΈ Precise Clip Trimming',
494
  'πŸ”Š Volume Control per Clip',
495
- 'πŸ”₯ SIMPLE Slowed+Reverb (Like YouTube/TikTok - Clean & Fast)',
 
496
  '❌ Zero Quality Loss'
497
  ],
498
  total_effects: Object.keys(EFFECTS).length,
499
  total_instruments: Object.keys(INSTRUMENTS).length,
500
- note: 'Slowed+Reverb is now SIMPLE - no complex analysis, just clean authentic sound like YouTube/TikTok!'
501
  });
502
  });
503
 
@@ -518,7 +532,8 @@ app.get('/effects', (req, res) => {
518
  description: EFFECTS[key].description,
519
  moods: EFFECTS[key].instrumentMoods || [],
520
  hasInstruments: EFFECTS[key].instrumentVolume > 0,
521
- isSimple: key === 'slowed_reverb'
 
522
  }))
523
  });
524
  });
@@ -564,7 +579,27 @@ app.post('/process', upload.single('audio'), async (req, res) => {
564
  let usedInstruments = [];
565
  let analysisDetails = null;
566
 
567
- if (effectType === 'slowed_reverb') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  console.log('\nπŸ”₯ Applying SIMPLE Slowed + Reverb (YouTube/TikTok style)...');
569
  console.log(' Speed: 85% (perfect slow)');
570
  console.log(' Pitch: 92% (deep voice)');
@@ -583,7 +618,55 @@ app.post('/process', upload.single('audio'), async (req, res) => {
583
  instruments: 'NONE',
584
  quality: 'YouTube/TikTok style - Clean & Professional'
585
  };
586
- } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
  if (addInstruments && effect.instrumentVolume > 0) {
588
  const selectedKeys = getSmartInstruments(effectType, 2);
589
  usedInstruments = selectedKeys.map(key => ({
@@ -638,7 +721,8 @@ app.post('/process', upload.single('audio'), async (req, res) => {
638
  description: effect.description,
639
  moods: effect.instrumentMoods || [],
640
  hasInstruments: effect.instrumentVolume > 0,
641
- isSimple: effectType === 'slowed_reverb'
 
642
  },
643
  instruments: usedInstruments,
644
  output: {
@@ -650,7 +734,6 @@ app.post('/process', upload.single('audio'), async (req, res) => {
650
 
651
  if (analysisDetails) {
652
  response.analysis = analysisDetails;
653
- response.message = `${response.message} (Simple & clean - YouTube/TikTok style)`;
654
  }
655
 
656
  console.log('\n═══════════════════════════════════════════════════════════');
@@ -798,13 +881,9 @@ app.post('/mashup/analyze/:sessionId', async (req, res) => {
798
  }
799
  });
800
 
801
- // ═══════════════════════════════════════════════════════════
802
- // βœ… FIXED /mashup/create ENDPOINT - Session ID Issue Fixed
803
- // ═══════════════════════════════════════════════════════════
804
  app.post('/mashup/create', async (req, res) => {
805
  const tempFiles = [];
806
  try {
807
- // βœ… FIX: Support both session_id (snake_case) and sessionId (camelCase)
808
  const { session_id, sessionId, arrangement, theme, transitions, forceCreate } = req.body;
809
  const actualSessionId = session_id || sessionId;
810
 
@@ -1057,15 +1136,15 @@ setInterval(() => {
1057
 
1058
  app.listen(PORT, '0.0.0.0', () => {
1059
  console.log('\n═══════════════════════════════════════════════════════════');
1060
- console.log('🎡 UNIFIED MASHUP API v14.0 - FIXED SESSION ID');
1061
  console.log('═══════════════════════════════════════════════════════════');
1062
  console.log(`πŸ“ Server: http://0.0.0.0:${PORT}`);
1063
  console.log('');
1064
- console.log('πŸ”₯ FEATURES:');
1065
  console.log('═══════════════════════════════════════════════════════════');
1066
- console.log('βœ… Session ID bug FIXED (supports both formats)');
1067
- console.log('βœ… Simple Slowed+Reverb (YouTube/TikTok style)');
1068
- console.log('βœ… 7 Audio Effects with smart instruments');
1069
  console.log('βœ… Genre detection & compatibility check');
1070
  console.log('βœ… Timeline mashup editor');
1071
  console.log('');
@@ -1073,10 +1152,23 @@ app.listen(PORT, '0.0.0.0', () => {
1073
  console.log('═══════════════════════════════════════════════════════════');
1074
  console.log('GET / - API Info');
1075
  console.log('GET /health - Health Check');
 
1076
  console.log('POST /process - Single song processing');
1077
  console.log('POST /mashup/upload - Upload 2 songs');
1078
  console.log('POST /mashup/analyze/:sessionId - Analyze');
1079
- console.log('POST /mashup/create - Create mashup βœ… FIXED');
1080
  console.log('GET /download/:filename - Download');
 
 
 
 
 
 
 
 
 
 
 
 
1081
  console.log('═══════════════════════════════════════════════════════════\n');
1082
  });
 
1
  // ═══════════════════════════════════════════════════════════
2
+ // COMPLETE UPDATED BACKEND SERVER
3
+ // Version 15.0 - Added "Slowed" Effect + Improved Bass Boost
4
  // ═══════════════════════════════════════════════════════════
5
 
6
  const express = require('express');
 
74
  }
75
  };
76
 
77
+ // βœ… UPDATED EFFECTS - Added "slowed" + Improved "bass_boosted"
78
  const EFFECTS = {
79
  lofi: {
80
  name: "LoFi Hip Hop",
 
83
  instrumentVolume: 0,
84
  instrumentMoods: ["chill", "sad_romantic", "ambient"]
85
  },
86
+
87
+ // βœ… NEW: Simple Slowed Effect (just makes song slower, no reverb)
88
+ slowed: {
89
+ name: "Slowed",
90
+ description: "Just slowed down - pure slow tempo (No instruments, no reverb)",
91
+ baseCommand: `atempo=0.80,asetrate=44100*0.90,aresample=44100,equalizer=f=800:t=q:width=2:g=1.5,highpass=f=35,lowpass=f=14000,volume=1.15`,
92
+ instrumentVolume: 0,
93
+ instrumentMoods: []
94
+ },
95
+
96
  slowed_reverb: {
97
  name: "Slowed + Reverb",
98
  description: "Simple & authentic - like YouTube/TikTok (clean vocals, no instruments)",
 
100
  instrumentVolume: 0,
101
  instrumentMoods: []
102
  },
103
+
104
  nightcore: {
105
  name: "Nightcore",
106
  description: "High energy with bright sparkling sounds (With Instruments)",
 
108
  instrumentVolume: 0.04,
109
  instrumentMoods: ["upbeat", "romantic"]
110
  },
111
+
112
  vaporwave: {
113
  name: "Vaporwave",
114
  description: "Retro nostalgic with dreamy sad vibes (With Instruments)",
 
116
  instrumentVolume: 0.005,
117
  instrumentMoods: ["sad_romantic", "ambient", "sad"]
118
  },
119
+
120
  "8d_audio": {
121
  name: "8D Audio",
122
  description: "Immersive 360Β° with ambient dreamy layers (With Instruments)",
 
124
  instrumentVolume: 0.05,
125
  instrumentMoods: ["ambient", "romantic", "sad_romantic"]
126
  },
127
+
128
+ // βœ… IMPROVED: Bass Boosted (smooth transitions, no noise, dynamic pulsing)
129
  bass_boosted: {
130
  name: "Bass Boosted",
131
+ description: "Smooth heavy bass with pulsing rhythm (Clean, no distortion)",
132
+ baseCommand: `bass=g=16:f=50:width_type=o:width=1.8,bass=g=12:f=90:width_type=h:width=100,equalizer=f=35:t=q:width=1:g=10,equalizer=f=70:t=q:width=1.5:g=8,equalizer=f=130:t=q:width=2:g=6,equalizer=f=450:t=q:width=2:g=-2.5,equalizer=f=3500:t=q:width=3.5:g=-4.5,acompressor=threshold=-24dB:ratio=6:attack=4:release=60:makeup=6,apulsator=hz=0.18:mode=sine:width=0.6,highpass=f=25,alimiter=limit=0.92:attack=6:release=65,volume=1.45`,
133
  instrumentVolume: 0.05,
134
  instrumentMoods: ["ambient", "chill"]
135
  },
136
+
137
  ambient: {
138
  name: "Ambient Chill",
139
  description: "Ethereal meditation with sad peaceful vibes (With Instruments)",
 
486
  return inputPath;
487
  }
488
  }
 
 
 
 
489
 
490
  // API ENDPOINTS
491
 
492
  app.get('/', (req, res) => {
493
  res.json({
494
  status: 'online',
495
+ message: '🎡 Unified Mashup API v15.0 - NEW SLOWED EFFECT',
496
+ version: '15.0',
497
  features: [
498
  '🎭 Smart Genre Detection (8 genres)',
499
  '🎬 CapCut-style Timeline Editor',
500
+ '🎨 8 Audio Effects (NEW: Pure Slowed)',
501
  'πŸ”€ Natural Crossfade',
502
+ '🎹 Smart Instrument Mixing',
503
  '🎡 BPM Detection & Tempo Matching',
504
  '🎯 Genre Compatibility Check',
505
  'πŸ“Š Frequency Spectrum Analysis',
506
  'βœ‚οΈ Precise Clip Trimming',
507
  'πŸ”Š Volume Control per Clip',
508
+ 'πŸ”₯ NEW: Pure Slowed Effect (just slow tempo)',
509
+ '🎚️ IMPROVED: Clean Bass Boost (smooth pulsing)',
510
  '❌ Zero Quality Loss'
511
  ],
512
  total_effects: Object.keys(EFFECTS).length,
513
  total_instruments: Object.keys(INSTRUMENTS).length,
514
+ note: 'NEW: Slowed effect added! Bass boost improved for smooth transitions!'
515
  });
516
  });
517
 
 
532
  description: EFFECTS[key].description,
533
  moods: EFFECTS[key].instrumentMoods || [],
534
  hasInstruments: EFFECTS[key].instrumentVolume > 0,
535
+ isNew: key === 'slowed',
536
+ isImproved: key === 'bass_boosted'
537
  }))
538
  });
539
  });
 
579
  let usedInstruments = [];
580
  let analysisDetails = null;
581
 
582
+ // βœ… Handle "slowed" effect (NEW)
583
+ if (effectType === 'slowed') {
584
+ console.log('\n🐌 Applying PURE SLOWED effect...');
585
+ console.log(' Speed: 80% (perfect slow)');
586
+ console.log(' Pitch: 90% (deeper tone)');
587
+ console.log(' NO REVERB, NO INSTRUMENTS');
588
+ console.log(' Just pure slowed tempo');
589
+
590
+ ffmpegCommand = `ffmpeg -i "${inputPath}" -threads 0 -af "${effect.baseCommand}" -ar 44100 -b:a 192k -preset ultrafast -y "${outputPath}"`;
591
+
592
+ analysisDetails = {
593
+ description: 'Pure slowed tempo',
594
+ speed: '80% (slower than slowed+reverb)',
595
+ pitch: '90% (deeper voice)',
596
+ reverb: 'NONE',
597
+ instruments: 'NONE',
598
+ quality: 'Simple & Clean - Just Slow'
599
+ };
600
+ }
601
+ // βœ… Handle "slowed_reverb" effect
602
+ else if (effectType === 'slowed_reverb') {
603
  console.log('\nπŸ”₯ Applying SIMPLE Slowed + Reverb (YouTube/TikTok style)...');
604
  console.log(' Speed: 85% (perfect slow)');
605
  console.log(' Pitch: 92% (deep voice)');
 
618
  instruments: 'NONE',
619
  quality: 'YouTube/TikTok style - Clean & Professional'
620
  };
621
+ }
622
+ // βœ… Handle "bass_boosted" effect (IMPROVED)
623
+ else if (effectType === 'bass_boosted') {
624
+ console.log('\nπŸ”Š Applying IMPROVED BASS BOOST...');
625
+ console.log(' Bass: Heavy but clean (16dB @ 50Hz)');
626
+ console.log(' Pulsing: Smooth rhythm (0.18Hz sine wave)');
627
+ console.log(' Compression: Dynamic & artifact-free');
628
+ console.log(' NO NOISE, NO DISTORTION');
629
+
630
+ if (addInstruments && effect.instrumentVolume > 0) {
631
+ const selectedKeys = getSmartInstruments(effectType, 2);
632
+ usedInstruments = selectedKeys.map(key => ({
633
+ id: key,
634
+ name: INSTRUMENTS[key].name,
635
+ mood: INSTRUMENTS[key].mood
636
+ }));
637
+
638
+ console.log(`🎹 Instruments: ${usedInstruments.map(i => i.name).join(', ')}`);
639
+
640
+ const timestamp = Date.now();
641
+ const inst1Path = path.join(outputsDir, `inst1-${timestamp}.wav`);
642
+ const inst2Path = path.join(outputsDir, `inst2-${timestamp}.wav`);
643
+
644
+ await execPromise(`ffmpeg -f lavfi -i "${INSTRUMENTS[selectedKeys[0]].command}" -t 12 -ar 44100 -y "${inst1Path}"`);
645
+ await execPromise(`ffmpeg -f lavfi -i "${INSTRUMENTS[selectedKeys[1]].command}" -t 12 -ar 44100 -y "${inst2Path}"`);
646
+
647
+ const vol = effect.instrumentVolume;
648
+ ffmpegCommand = `ffmpeg -i "${inputPath}" -stream_loop -1 -i "${inst1Path}" -stream_loop -1 -i "${inst2Path}" -filter_complex "[0:a]volume=3.5[main];[1:a]volume=${vol}[i1];[2:a]volume=${vol}[i2];[main][i1][i2]amix=inputs=3:duration=first:dropout_transition=2:weights=15 0.5 0.5,${effect.baseCommand}" -ar 44100 -b:a 192k -preset ultrafast -threads 0 -y "${outputPath}"`;
649
+
650
+ setTimeout(() => {
651
+ [inst1Path, inst2Path].forEach(p => {
652
+ if (fs.existsSync(p)) fs.unlinkSync(p);
653
+ });
654
+ }, 5000);
655
+ } else {
656
+ console.log('⏭️ Instruments skipped for this effect');
657
+ ffmpegCommand = `ffmpeg -i "${inputPath}" -threads 0 -af "${effect.baseCommand}" -ar 44100 -b:a 192k -preset ultrafast -y "${outputPath}"`;
658
+ }
659
+
660
+ analysisDetails = {
661
+ description: 'Smooth heavy bass with pulsing',
662
+ bass: 'Deep & powerful (16dB @ 50Hz, 12dB @ 90Hz)',
663
+ pulsing: 'Smooth sine wave rhythm (0.18Hz)',
664
+ compression: 'Dynamic (6:1 ratio, clean transitions)',
665
+ quality: 'No noise, no distortion - Pure bass'
666
+ };
667
+ }
668
+ // βœ… Handle other effects
669
+ else {
670
  if (addInstruments && effect.instrumentVolume > 0) {
671
  const selectedKeys = getSmartInstruments(effectType, 2);
672
  usedInstruments = selectedKeys.map(key => ({
 
721
  description: effect.description,
722
  moods: effect.instrumentMoods || [],
723
  hasInstruments: effect.instrumentVolume > 0,
724
+ isNew: effectType === 'slowed',
725
+ isImproved: effectType === 'bass_boosted'
726
  },
727
  instruments: usedInstruments,
728
  output: {
 
734
 
735
  if (analysisDetails) {
736
  response.analysis = analysisDetails;
 
737
  }
738
 
739
  console.log('\n═══════════════════════════════════════════════════════════');
 
881
  }
882
  });
883
 
 
 
 
884
  app.post('/mashup/create', async (req, res) => {
885
  const tempFiles = [];
886
  try {
 
887
  const { session_id, sessionId, arrangement, theme, transitions, forceCreate } = req.body;
888
  const actualSessionId = session_id || sessionId;
889
 
 
1136
 
1137
  app.listen(PORT, '0.0.0.0', () => {
1138
  console.log('\n═══════════════════════════════════════════════════════════');
1139
+ console.log('🎡 UNIFIED MASHUP API v15.0 - NEW SLOWED EFFECT');
1140
  console.log('═══════════════════════════════════════════════════════════');
1141
  console.log(`πŸ“ Server: http://0.0.0.0:${PORT}`);
1142
  console.log('');
1143
+ console.log('πŸ”₯ NEW FEATURES:');
1144
  console.log('═══════════════════════════════════════════════════════════');
1145
+ console.log('βœ… NEW: Pure "Slowed" effect (just slow tempo)');
1146
+ console.log('βœ… IMPROVED: Clean Bass Boost (smooth pulsing)');
1147
+ console.log('βœ… 8 Total effects with smart instruments');
1148
  console.log('βœ… Genre detection & compatibility check');
1149
  console.log('βœ… Timeline mashup editor');
1150
  console.log('');
 
1152
  console.log('═══════════════════════════════════════════════════════════');
1153
  console.log('GET / - API Info');
1154
  console.log('GET /health - Health Check');
1155
+ console.log('GET /effects - List all effects (includes new slowed)');
1156
  console.log('POST /process - Single song processing');
1157
  console.log('POST /mashup/upload - Upload 2 songs');
1158
  console.log('POST /mashup/analyze/:sessionId - Analyze');
1159
+ console.log('POST /mashup/create - Create mashup');
1160
  console.log('GET /download/:filename - Download');
1161
+ console.log('═══════════════════════════════════════════════════════════');
1162
+ console.log('');
1163
+ console.log('🎨 AVAILABLE EFFECTS:');
1164
+ console.log('═══════════════════════════════════════════════════════════');
1165
+ console.log('1. lofi - LoFi Hip Hop');
1166
+ console.log('2. slowed πŸ†• - Pure Slowed (just slow tempo)');
1167
+ console.log('3. slowed_reverb - Slowed + Reverb');
1168
+ console.log('4. nightcore - Nightcore');
1169
+ console.log('5. vaporwave - Vaporwave');
1170
+ console.log('6. 8d_audio - 8D Audio');
1171
+ console.log('7. bass_boosted ⭐ - Bass Boost (IMPROVED)');
1172
+ console.log('8. ambient - Ambient Chill');
1173
  console.log('═══════════════════════════════════════════════════════════\n');
1174
  });