Advanced FLAC authenticity analyzer - Detects MP3-to-FLAC transcodes with high precision
Project description
๐ต FLAC Detective
Advanced FLAC Authenticity Analyzer for Detecting MP3-to-FLAC Transcodes
FLAC Detective is a professional-grade command-line tool that analyzes FLAC audio files to detect MP3-to-FLAC transcodes with high precision. Using advanced spectral analysis and an 11-rule scoring system, it helps you maintain an authentic lossless music collection.
โจ Key Features
- ๐ฏ High Precision Detection: 11-rule scoring system with intelligent protection mechanisms
- ๐ 4-Level Verdict System: Clear confidence ratings from AUTHENTIC to FAKE_CERTAIN
- โก Performance Optimized: 80% faster than baseline through smart caching and parallel processing
- ๐ Advanced Analysis: Spectral analysis, compression artifact detection, and multi-segment validation
- ๐ก๏ธ Protection Layers: Prevents false positives for vinyl rips, cassette transfers, and high-quality MP3s
- ๐ Flexible Output: Console reports with Rich formatting, JSON export, and detailed logging
- ๐ง Graceful Error Handling: Partial file reading for corrupted or problematic FLAC files
๐ Quick Start
Installation
pip install flac-detective
Basic Usage
# Analyze current directory
flac-detective .
# Analyze specific directory
flac-detective /path/to/music
# Generate JSON report
flac-detective /path/to/music --format json
# Verbose output with detailed analysis
flac-detective /path/to/music --verbose
๐ How It Works
Detection Rules
FLAC Detective uses 11 independent rules with additive scoring (0-150 points):
| Rule | Description | Points |
|---|---|---|
| Rule 1 | MP3 Spectral Signature (CBR patterns) | +50 |
| Rule 2 | Cutoff Frequency Analysis | +50 |
| Rule 3 | Bitrate Inflation Detection | +50 |
| Rule 4 | Suspicious 24-bit Detection | +30 |
| Rule 5 | High Variance Protection (VBR) | -40 |
| Rule 6 | High Quality Protection | -30 |
| Rule 7 | Vinyl & Silence Analysis | -100 |
| Rule 8 | Nyquist Exception | -50 |
| Rule 9 | Compression Artifacts | +30 |
| Rule 10 | Multi-Segment Consistency | Variable |
| Rule 11 | Cassette Detection | -60 |
Verdict System
Based on the total score, FLAC Detective assigns one of four verdicts:
Score โค 30 โ โ
AUTHENTIC (High confidence - genuine lossless)
Score 31-60 โ โก WARNING (Manual review recommended)
Score 61-85 โ โ ๏ธ SUSPICIOUS (Likely transcode)
Score โฅ 86 โ โ FAKE_CERTAIN (Definite transcode)
Protection Mechanisms
The tool implements a multi-layer protection system to prevent false positives:
- Absolute Protection (Rule 8): Protects files with cutoff near Nyquist frequency
- MP3 320k Protection (Rule 1): Exception for high-quality MP3 320 kbps
- Analog Source Protection (Rules 7, 11): Detects vinyl rips and cassette transfers
- Dynamic Protection (Rule 10): Validates consistency across file segments
๐ What's New in v0.7.0
Partial File Reading
- Gracefully handles FLAC files with decoder errors
- Analyzes partial audio data when full decode fails
- Reduces false "CORRUPTED" verdicts
Energy-Based Cutoff Detection
- Critical Fix: Bass-heavy music no longer misidentified as MP3
- Added 15 kHz minimum threshold to distinguish bass from MP3 artifacts
- Impact: 77% reduction in false positives
Quality Improvements
- False positives: 198 โ 46 (-77%)
- Authentic detection: 59 โ 244 (+314%)
- Overall quality score: 20.2% โ 83.6%
๐ป Usage Examples
Command Line
# Basic analysis
flac-detective /path/to/music
# Save report to file
flac-detective /path/to/music --output report.txt
# JSON output for automation
flac-detective /path/to/music --format json > results.json
# Verbose mode with detailed rule execution
flac-detective /path/to/music --verbose
Python API
from flac_detective.analysis.new_scoring import new_calculate_score
from pathlib import Path
# Analyze a FLAC file
filepath = Path("/path/to/file.flac")
score, verdict, confidence, reasons = new_calculate_score(
cutoff_freq=20500,
metadata={"sample_rate": 44100, "bit_depth": 16, "channels": 2},
duration_check={"duration": 180.5},
filepath=filepath
)
print(f"Verdict: {verdict}")
print(f"Score: {score}/150")
print(f"Confidence: {confidence}")
print(f"Detection Reasons: {reasons}")
๐ฆ Requirements
Python Dependencies
- Python 3.8 or higher
- numpy >= 1.20.0
- scipy >= 1.7.0
- mutagen >= 1.45.0
- soundfile >= 0.10.0
- rich >= 13.0.0
Optional System Dependencies
The flac command-line tool is recommended for advanced features:
Linux (Debian/Ubuntu):
sudo apt-get install flac
macOS:
brew install flac
Windows: Download from Xiph.org FLAC
๐๏ธ Development
Installation from Source
# Clone the repository
git clone https://github.com/GuillainM/FLAC_Detective.git
cd FLAC_Detective
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Linux/macOS:
source venv/bin/activate
# Windows:
venv\Scripts\activate
# Install in development mode
pip install -e ".[dev]"
Running Tests
# Run all tests
pytest
# Run with coverage report
pytest --cov=flac_detective --cov-report=html
# Run specific test file
pytest tests/test_new_scoring_rules.py -v
Project Structure
src/flac_detective/
โโโ analysis/
โ โโโ new_scoring/ # 11-rule scoring system
โ โ โโโ rules/ # Individual rule implementations
โ โ โโโ calculator.py # Score orchestration
โ โ โโโ verdict.py # Score interpretation
โ โโโ spectrum.py # Spectral analysis
โ โโโ audio_cache.py # Optimized file reading
โโโ reporting/ # Report generation
โโโ main.py # CLI entry point
๐ Documentation
- Changelog - Version history and release notes
- Technical Documentation - Architecture and algorithms
- Rule Specifications - Detailed rule documentation
- Performance Guide - Optimization strategies
- Project Structure - Codebase organization
๐ฏ Use Cases
โ Ideal For
- Library Maintenance: Clean your music collection of fake lossless files
- Quality Verification: Validate FLAC authenticity before archiving
- Batch Processing: Analyze large music libraries efficiently
- Format Validation: Ensure genuine lossless quality for critical listening
โ ๏ธ Limitations
- Only analyzes FLAC files (other lossless formats not supported)
- Designed for batch analysis, not real-time processing
- Detects transcodes, not subjective audio quality
- May require manual review for edge cases (WARNING verdicts)
๐ค Contributing
Contributions are welcome! Here's how you can help:
- Report Issues: Found a bug? Open an issue
- Suggest Features: Have an idea? Start a discussion
- Submit PRs: Fork the repo, create a feature branch, and submit a pull request
- Improve Docs: Documentation improvements are always appreciated
Development Workflow
# Fork and clone the repository
git clone https://github.com/YOUR_USERNAME/FLAC_Detective.git
cd FLAC_Detective
# Create feature branch
git checkout -b feature/amazing-feature
# Make changes and test
pytest
# Format code
black src tests
isort src tests
# Commit and push
git commit -m "Add amazing feature"
git push origin feature/amazing-feature
# Open Pull Request on GitHub
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Audio analysis community for MP3 compression research
- Contributors to NumPy, SciPy, and Soundfile libraries
- Beta testers and community feedback
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Project Wiki
FLAC Detective v0.7.0 - Maintaining authentic lossless audio collections
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flac_detective-0.7.2.tar.gz.
File metadata
- Download URL: flac_detective-0.7.2.tar.gz
- Upload date:
- Size: 146.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de04a77829c18854cab18edb926d7fb101ac2ded2bcb28ace5d78f12caf64d67
|
|
| MD5 |
070d4a75d772d61441854e37778171b5
|
|
| BLAKE2b-256 |
896aebd7b480a1aa024a6d886493078511e0f3c4a4947af24ed2f67a83b4a9b6
|
File details
Details for the file flac_detective-0.7.2-py3-none-any.whl.
File metadata
- Download URL: flac_detective-0.7.2-py3-none-any.whl
- Upload date:
- Size: 93.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88cabdd14fc4f4d564bcf7813309375b1c9077bfcd0beb0ed2b44f15c53a66ad
|
|
| MD5 |
5bd9edd01210add377ca797501a026fc
|
|
| BLAKE2b-256 |
092b13f0f592c141129d0f7d393db9369af0324f34c4bd428846fd9c1a3130b7
|