From 5f8b55d898446fdaa9f9d4ab3506d2162dd684d3 Mon Sep 17 00:00:00 2001 From: Tristan Date: Tue, 13 May 2025 10:48:24 -0400 Subject: [PATCH] script for converting flac to mp3 --- convert.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ github_mirror.py | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 convert.py diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..a37cb05 --- /dev/null +++ b/convert.py @@ -0,0 +1,55 @@ +import os +import subprocess + +def convert_flac_to_mp3(input_dir=".", output_dir="mp3_output"): + """ + Converts all FLAC files in a directory (and its subdirectories) + to 320 kbps MP3 files in a specified output directory. + + Args: + input_dir (str): The directory to search for FLAC files. + Defaults to the current directory. + output_dir (str): The directory to save the converted MP3 files. + Defaults to 'mp3_output'. + """ + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + for root, _, files in os.walk(input_dir): + for file in files: + if file.lower().endswith(".flac"): + flac_path = os.path.join(root, file) + # Create the corresponding output directory structure + relative_path = os.path.relpath(root, input_dir) + target_output_dir = os.path.join(output_dir, relative_path) + if not os.path.exists(target_output_dir): + os.makedirs(target_output_dir) + + base_name = os.path.splitext(file)[0] + mp3_path = os.path.join(target_output_dir, f"{base_name}.mp3") + + print(f"Converting \"{flac_path}\" to \"{mp3_path}\"...") + + # ffmpeg command + command = [ + "ffmpeg", + "-i", flac_path, + "-ab", "320k", + "-map_metadata", "0", + "-id3v2_version", "3", + mp3_path + ] + + try: + subprocess.run(command, check=True, capture_output=True, text=True) + print(f"Successfully converted \"{flac_path}\"") + except subprocess.CalledProcessError as e: + print(f"Error converting \"{flac_path}\": {e}") + print(f"Stderr: {e.stderr}") + print("-" * 20) # Separator + + print("Conversion process finished.") + +if __name__ == "__main__": + # You can change the input_dir and output_dir here if needed + convert_flac_to_mp3() diff --git a/github_mirror.py b/github_mirror.py index 11d43dc..dc1aa5b 100644 --- a/github_mirror.py +++ b/github_mirror.py @@ -157,7 +157,7 @@ def main(): logging.info("Successfully fetched updates from local server.") logging.info(f"Pushing mirror of '{repo_name}' to GitHub remote: '{github_repo_url}'") - run_command(["git", "config", "--global", "--add", "safe.directory"], cwd=local_mirror_clone_path) + run_command(["git", "push", "--mirror", "github"], cwd=local_mirror_clone_path) logging.info(f"Successfully mirrored '{repo_name}' to GitHub.")