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",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node 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
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user