modules.addons.rename

Audio File Renamer

A tool to rename audio files to a standardized format: “(track name) - (album)” while removing special characters that can cause issues with music players.

For file names, includes: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]()-_~@=+

Functions

main()

Main function for the audio renamer.

parse_arguments()

Parse command line arguments.

parse_character_replacements(replace_char_list)

Parse character replacement arguments from command line.

Classes

AudioRenamer(options)

Audio file renamer that standardizes filenames based on metadata

class modules.addons.rename.AudioRenamer(options: Dict[str, Any])[source]

Bases: object

Audio file renamer that standardizes filenames based on metadata

Initialize the AudioRenamer with the specified options.

Parameters:

options (dict) – Dictionary of renaming options

__init__(options: Dict[str, Any])[source]

Initialize the AudioRenamer with the specified options.

Parameters:

options (dict) – Dictionary of renaming options

sanitize_filename(text: str) str[source]

Clean a string to be safe for use as a filename.

Parameters:

text (str) – Text to sanitize

Returns:

Sanitized text

Return type:

str

get_file_metadata(filepath: str) Dict[str, str][source]

Extract metadata from an audio file using FFprobe.

Parameters:

filepath (str) – Path to the audio file

Returns:

Dictionary containing all available metadata

Return type:

dict

generate_new_filename(filepath: str) str | None[source]

Generate a new filename based on metadata using the specified format.

Parameters:

filepath (str) – Path to the audio file

Returns:

New filename, or None if format cannot be resolved

Return type:

str or None

rename_file(filepath: str) bool[source]

Rename a single audio file based on its metadata.

Parameters:

filepath (str) – Path to the audio file

Returns:

True if rename was successful, False otherwise

Return type:

bool

rename_directory(directory: str) tuple[int, int][source]

Rename all audio files in a directory.

Parameters:

directory (str) – Directory containing audio files

Returns:

(number of successful renames, total number of files processed)

Return type:

tuple

modules.addons.rename.parse_arguments()[source]

Parse command line arguments.

Returns:

Parsed arguments

Return type:

argparse.Namespace

modules.addons.rename.parse_character_replacements(replace_char_list, no_defaults=False)[source]

Parse character replacement arguments from command line.

Parameters:
  • replace_char_list (list) – List of [old_char, new_char] pairs

  • no_defaults (bool) – If True, don’t include default replacements

Returns:

Dictionary mapping old characters to new characters

Return type:

dict

modules.addons.rename.main()[source]

Main function for the audio renamer.