First commit
This commit is contained in:
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