From 9bcfb91408f81220f4a4b318a7935e0625f163d9 Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Sat, 6 Dec 2025 20:54:53 -0600 Subject: [PATCH] working --- backend/convert-to-mp3.py | 43 +++++++++++++++++++++++++++++++++++++++ backend/package.json | 1 + backend/server.js | 11 +++++----- frontend/src/app.jsx | 8 ++++---- 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 backend/convert-to-mp3.py diff --git a/backend/convert-to-mp3.py b/backend/convert-to-mp3.py new file mode 100644 index 0000000..594a3a1 --- /dev/null +++ b/backend/convert-to-mp3.py @@ -0,0 +1,43 @@ +# convert_to_mp3.py +import os + +from pydub import AudioSegment + +# Directory relative to this script +MUSIC_DIR = os.path.join(os.path.dirname(__file__), "music") + +# Supported input formats +INPUT_FORMATS = [".flac", ".wav", ".m4a", ".ogg"] + + +def convert_to_mp3(file_path): + file_root, ext = os.path.splitext(file_path) + ext = ext.lower() + + if ext not in INPUT_FORMATS: + return # skip unsupported formats + + mp3_path = f"{file_root}.mp3" + + print(f"Converting {file_path} → {mp3_path}") + + # Load audio + audio = AudioSegment.from_file(file_path) + + # Export as MP3 + audio.export(mp3_path, format="mp3", bitrate="320k") + + # Delete original file + os.remove(file_path) + print(f"Deleted original: {file_path}") + + +def main(): + for root, _, files in os.walk(MUSIC_DIR): + for file in files: + full_path = os.path.join(root, file) + convert_to_mp3(full_path) + + +if __name__ == "__main__": + main() diff --git a/backend/package.json b/backend/package.json index bf3b8f7..4dbfd9d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,7 @@ { "name": "music-backend", "version": "1.0.0", + "type": "module", "main": "server.js", "scripts": { "start": "node server.js", diff --git a/backend/server.js b/backend/server.js index 0d61a4d..38b020a 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1,9 +1,8 @@ -// server.js -const express = require('express'); -const path = require('path'); -const fs = require('fs/promises'); -const mm = require('music-metadata'); -const cors = require('cors'); +import express from 'express'; +import path from 'path'; +import fs from 'fs/promises'; +import * as mm from 'music-metadata'; +import cors from 'cors'; const app = express(); app.use(cors()); // adjust for production if needed diff --git a/frontend/src/app.jsx b/frontend/src/app.jsx index 1327c0c..cc0c8af 100644 --- a/frontend/src/app.jsx +++ b/frontend/src/app.jsx @@ -8,13 +8,13 @@ export default function App() { // Hard-coded featured tracks (filenames only) const FEATURED = [ - "Kanne Kalimaane__Moondram Pirai__Unplucked Instrumental Studio Music Cover__2025-06-26.flac", - "Pudhu Vellai Mazhai__Roja__Unplucked Instrumental Studio Music Cover__2025-03-15.flac", - "Porkalam and Kannana Kanney Medley__Thenali and Viswasam__Unplucked Instrumental Studio Music Cover__2025-01-01.flac" + "Kanne Kalimaane__Moondram Pirai__Unplucked Instrumental Studio Music Cover__2025-06-26.mp3", + "Pudhu Vellai Mazhai__Roja__Unplucked Instrumental Studio Music Cover__2025-03-15.mp3", + "Porkalam and Kannana Kanney Medley__Thenali and Viswasam__Unplucked Instrumental Studio Music Cover__2025-01-01.mp3" ]; useEffect(() => { - axios.get("http://localhost:3001/api/tracks").then(res => { + axios.get('/api/tracks').then(res => { setAllTracks(res.data.tracks); }); }, []);