- Overview
- Features
- Installation
- Dependencies
- Usage
- Logging
- Caching Mechanism
- Contributing
- License
- Contact
LoudnessSorter is a Python script designed to analyze and sort audio files based on their integrated loudness (LUFS). It recursively scans a specified directory for audio files, calculates their loudness, caches the results for efficiency, and outputs a sorted list from the quietest to the loudest tracks.
- Recursive Audio File Scanning: Supports multiple audio formats including MP3, WAV, FLAC, and OGG.
- Integrated Loudness Calculation: Utilizes the pyloudnorm library to compute LUFS values.
- Caching Mechanism: Stores loudness calculations to avoid redundant processing, enhancing performance.
- Parallel Processing: Leverages multi-threading to process multiple files simultaneously, reducing execution time.
- Comprehensive Logging: Logs processing details and errors to both console and a log file.
- Command-Line Interface: Easy-to-use CLI with customizable options for directories and cache files.
-
Clone the Repository
git clone https://github.com/marcoherrera-s/LoudnessSorter.git cd LoudnessSorter
-
Create a Virtual Environment (Optional but Recommended)
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
pip install pyloudnorm soundfile tqdm
The script relies on the following Python packages:
- pyloudnorm: For loudness normalization and measurement.
- soundfile: For reading and writing sound files.
- tqdm: For displaying progress bars.
Ensure you have Python 3.7 or higher installed.
The script can be executed via the command line with various options to customize its behavior.
-
-c
,--carpeta
: (Optional) Path to the directory containing the audio files.
Default:/your/default/directory
(edit this in the pyloud.py) -
-cache
,--ruta_cache
: (Optional) Path to the JSON file used for caching loudness values.
Default:loudness_cache.json
-
Basic Usage with Default Settings
python loudness_sorter.py
This command will process audio files located in
/your/default/directory
and useloudness_cache.json
for caching. -
Specify a Custom Audio Directory
python loudness_sorter.py --folder "/path/to/your/music"
-
Specify a Custom Cache File
python loudness_sorter.py --cache_path "my_cache.json"
-
Combine Custom Directory and Cache File
python loudness_sorter.py --folder "/path/to/your/music" --cache_path "my_cache.json"
The script implements a robust logging system that records both informational messages and errors. Logs are output to the console and saved to a file named procesamiento_loudness.log
in the script's directory.
- INFO: General processing information such as the number of new songs detected and sorted.
- ERROR: Issues encountered during file reading or loudness calculation.
To optimize performance, LoudnessSorter caches the loudness values of processed audio files in a JSON file (loudness_cache.json
by default). This ensures that only new or modified files are reprocessed in subsequent runs.
- Loading Cache: On execution, the script loads existing cache data if the cache file exists.
- Filtering Cache: It verifies that cached files still exist in the specified directory, removing any stale entries.
- Processing New Files: Only audio files not present in the cache are processed to calculate their loudness.
- Updating Cache: After processing, the cache file is updated with new loudness values.
For any questions, suggestions, feel free to reach out:
- Email: [email protected]
Happy Sorting!