working
This commit is contained in:
43
backend/convert-to-mp3.py
Normal file
43
backend/convert-to-mp3.py
Normal file
@@ -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()
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "music-backend",
|
"name": "music-backend",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
// server.js
|
import express from 'express';
|
||||||
const express = require('express');
|
import path from 'path';
|
||||||
const path = require('path');
|
import fs from 'fs/promises';
|
||||||
const fs = require('fs/promises');
|
import * as mm from 'music-metadata';
|
||||||
const mm = require('music-metadata');
|
import cors from 'cors';
|
||||||
const cors = require('cors');
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors()); // adjust for production if needed
|
app.use(cors()); // adjust for production if needed
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ export default function App() {
|
|||||||
|
|
||||||
// Hard-coded featured tracks (filenames only)
|
// Hard-coded featured tracks (filenames only)
|
||||||
const FEATURED = [
|
const FEATURED = [
|
||||||
"Kanne Kalimaane__Moondram Pirai__Unplucked Instrumental Studio Music Cover__2025-06-26.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.flac",
|
"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.flac"
|
"Porkalam and Kannana Kanney Medley__Thenali and Viswasam__Unplucked Instrumental Studio Music Cover__2025-01-01.mp3"
|
||||||
];
|
];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get("http://localhost:3001/api/tracks").then(res => {
|
axios.get('/api/tracks').then(res => {
|
||||||
setAllTracks(res.data.tracks);
|
setAllTracks(res.data.tracks);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user