commit 12771ecc75f753515c00a9753822ee2ad86e34a5 Author: Justine Date: Mon Apr 27 16:55:20 2026 +0200 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9090b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +myenv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..47a6075 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Music Library Converter + +A lightweight Python script that copies a music directory structure and automatically converts FLAC files to high-quality MP3s. + +## Requirements +- Python 3 +- `ffmpeg` installed and available in your system `PATH` + +## Usage +1. Open the script and update the `source` and `dest` paths at the top. +2. Run it: + ```bash + python3 convert_music.py + ``` + +## How It Works +- Recreates the exact folder structure in the destination directory. +- Copies all files over. +- Converts `.flac` → `.mp3` (320kbps, preserves ID3 metadata). +- Deletes the original `.flac` file after conversion. + +## ⚠️ Notes +- Paths are hardcoded at the top for simplicity. +- Designed for personal/local use. **Always back up your library before running!** diff --git a/convert.py b/convert.py new file mode 100755 index 0000000..468e515 --- /dev/null +++ b/convert.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +#coding: utf-8 + +import os +import shutil +import subprocess +import sys + +source = "/home/justine/NAS/Musique" +dest = "/home/justine/Music/Converted" + +# 1 - Copy the folder structure + +for path, directories, files in os.walk(source): + + for d in directories: + orig_path = str(os.path.join(path,d)) + new_path = orig_path.replace(source, dest) + print(f"1 - Creating {new_path}") + os.makedirs(new_path, exist_ok=True) + +# 2 - Copy and Convert if needed + + for f in files: + file_path = str(os.path.join(path, f)) + new_file_path = file_path.replace(source, dest) + print(f"2 - Copying {f}") + shutil.copyfile(file_path, new_file_path) + new_file_dir = new_file_path.replace(f, "") + + if "justine/NAS" in new_file_dir: + print("ERROOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOR") + sys.exit(1) + + if f.endswith(".flac"): + new_file_after = new_file_path.replace(".flac", ".mp3") + print(f"3 - Converting {f}") + os.chdir(new_file_dir) + command = f"/usr/bin/ffmpeg -i \"{f}\" -ab 320k -map_metadata 0 -id3v2_version 3 \"{f.replace(".flac", ".mp3")}\"" + print(subprocess.run(command, shell=True, check=False, capture_output=True)) + os.remove(f)