First commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
myenv
|
||||||
24
README.md
Normal file
24
README.md
Normal file
@ -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!**
|
||||||
41
convert.py
Executable file
41
convert.py
Executable file
@ -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)
|
||||||
Reference in New Issue
Block a user