Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

300 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎧 Audiobook to Audible (A2A)

A powerful CLI tool for managing audiobook libraries via Audiobookshelf and Audible APIs

CI Python 3.12+ Code style: black License: MIT Pre-commit CodeRabbit Pull Request Reviews

Features β€’ Quick Start β€’ Usage β€’ Architecture β€’ Security β€’ Contributing


Analyze audio quality β€’ Find upgrade candidates β€’ Enrich with Audible metadata β€’ Track series completion

✨ Features

πŸ” Quality Analysis

Analyze audio quality (bitrate, codec, format) across your entire library with intelligent tier classification.

πŸ“Š Upgrade Recommendations

Identify low-quality audiobooks and find matching Audible versions with pricing data.

πŸ”— Audible Integration

Seamless authentication, library access, catalog search, and metadata enrichment.

πŸ“š Series Management

Track series completion, find missing books, and match ABS series with Audible catalogs.

πŸ’Ύ Smart Caching

SQLite-based caching with TTL and namespaces to minimize API calls and speed up operations.

🎨 Rich CLI Experience

Beautiful terminal output with progress bars, styled tables, spinners, and visual feedback.

πŸ“‹ Requirements

Requirement Version Notes
Python 3.12+ Tested on 3.12 and 3.13
Audiobookshelf Any Self-hosted audiobook server
Audible Account β€” For enrichment features
mediainfo Any System package for audio analysis

πŸš€ Quick Start

# Clone and setup
git clone https://github.com/H2OKing89/a2a.git && cd a2a
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

# Configure
cp config.yaml.example config.yaml
# Edit config.yaml with your ABS URL and API key

# Verify connection
python cli.py status
πŸ“¦ Detailed Installation

1. Clone the repository

git clone https://github.com/H2OKing89/a2a.git
cd a2a

2. Create a virtual environment

python -m venv .venv
source .venv/bin/activate  # Linux/macOS
# or
.venv\Scripts\activate     # Windows

3. Install dependencies

# Production only
make install

# With development tools
make install-dev

4. Install system dependencies

# Ubuntu/Debian
sudo apt install mediainfo

# macOS
brew install mediainfo

# Arch Linux
sudo pacman -S mediainfo

5. Configure the tool

Copy the example configuration:

cp config.yaml.example config.yaml

Or use environment variables (.env file):

ABS_URL=https://your-audiobookshelf-server:13378
ABS_API_KEY=your-api-key
AUDIBLE_AUTH_FILE=data/audible_auth.json

πŸ“– Usage

Command Structure

cli.py
β”œβ”€β”€ status              # Global status (ABS + Audible + Cache)
β”œβ”€β”€ cache               # Manage unified SQLite cache
β”œβ”€β”€ abs                 # πŸ“š Audiobookshelf commands
β”œβ”€β”€ audible             # 🎧 Audible commands  
β”œβ”€β”€ quality             # πŸ’Ž Quality analysis commands
└── series              # πŸ“– Series management commands

Core Commands

πŸ“š Audiobookshelf (ABS)
# Check connection
python cli.py abs status

# List libraries
python cli.py abs libraries

# Browse items with filtering
python cli.py abs items <library-id> --limit 50

# Search your library
python cli.py abs search <library-id> "Harry Potter"

# View item details
python cli.py abs item <item-id>

# Export library to JSON
python cli.py abs export <library-id> -o library.json
Command Description
status Check ABS connection status
libraries List all libraries
stats Show library statistics
items List library items
item Show details for a specific item
search Search a library
export Export all library items to JSON
authors List authors in the library
series List series in the library
collections Manage ABS collections
🎧 Audible
# Authenticate (encrypted by default)
python cli.py audible login

# Check status and encryption
python cli.py audible status

# Browse your library
python cli.py audible library --limit 20

# Search Audible catalog
python cli.py audible search "Brandon Sanderson"

# View listening stats
python cli.py audible stats

# Get recommendations
python cli.py audible recommendations
Command Description
login Login to Audible and save credentials
encrypt Encrypt existing Audible credentials
status Check connection and encryption status
library List your Audible library
item Show details for an audiobook by ASIN
search Search the Audible catalog
export Export full library to JSON
wishlist Manage your Audible wishlist
stats Show listening statistics
recommendations Show personalized recommendations
πŸ’Ž Quality Analysis
# Scan library for quality metrics
python cli.py quality scan <library-id>

# Find low-quality items (below threshold)
python cli.py quality low <library-id> --threshold 128

# Analyze single item
python cli.py quality item <item-id>

# Find upgrade candidates with Audible pricing
python cli.py quality upgrades <library-id>
Command Description
scan Scan library for audio quality analysis
low List low quality audiobooks below threshold
item Analyze quality of a specific item
upgrades Find upgrade candidates with Audible pricing
πŸ“– Series Management
# List all series
python cli.py series list <library-id>

# Analyze series completion
python cli.py series analyze <library-id>

πŸ’Ž Quality Tiers

A2A uses an intelligent tier system to classify audio quality:

Tier Icon Criteria Description
Excellent πŸ’Ž Dolby Atmos OR 256+ kbps Premium quality, spatial audio
Better ✨ M4B @ 128-255 kbps High quality AAC in container
Good πŸ‘ M4B @ 110-127 kbps OR MP3 @ 128+ kbps Acceptable quality
Low πŸ‘Ž M4B @ 64-109 kbps OR MP3 @ 110-127 kbps Below recommended
Poor πŸ’© < 64 kbps OR MP3 < 110 kbps Needs replacement

Format Priority: M4B/M4A (AAC) > MP3 at equivalent bitrates due to codec efficiency.

πŸ—οΈ Architecture

src/
β”œβ”€β”€ abs/          # Audiobookshelf API client (sync + async)
β”œβ”€β”€ audible/      # Audible API client with encryption
β”œβ”€β”€ cache/        # SQLite caching layer (TTL, namespaces)
β”œβ”€β”€ cli/          # Typer CLI command modules
β”œβ”€β”€ quality/      # Audio quality analysis engine
β”œβ”€β”€ series/       # Series matching and tracking
β”œβ”€β”€ output/       # Report formatters (JSON, table, etc.)
└── utils/        # UI helpers, sample data generation

Key Components

Component Description
ABSClient Sync/async client for Audiobookshelf API with rate limiting
AudibleClient Client for Audible API with encrypted credential storage
QualityAnalyzer Audio quality tier calculation with configurable thresholds
SeriesMatcher Fuzzy matching between ABS and Audible series
SQLiteCache Unified caching with TTL, namespaces, and FTS support

Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ABS Library │────▢│ QualityAnalyzer │────▢│ AudioQuality     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β–Ό
β”‚   Audible   │────▢│ EnrichmentSvc   β”‚β”€β”€β”€β”€β–Άβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Catalog   β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚ Upgrade Report   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”’ Security

βœ… Credential Protection

  • Encrypted storage: AES-CBC encryption for Audible credentials
  • Secure permissions: Auth files set to 600 (owner-only)
  • Password protection: Via environment variable or prompt

βœ… Network Security

  • HTTPS by default: Auto-upgrades connections
  • Localhost exception: HTTP allowed for local development
  • Custom CA support: For self-signed certificates
# Encrypt existing credentials
python cli.py audible encrypt

# Check encryption status
python cli.py audible status

⚠️ Never commit config.yaml, data/audible_auth.json, or .env files. Use the provided .example files as templates.

πŸ” Security Configuration
# config.yaml
abs:
  host: https://abs.example.com
  api_key: "..."
  allow_insecure_http: false      # Only localhost over HTTP
  tls_ca_bundle: "/path/to/ca.pem"  # For self-signed certs

audible:
  auth_file: ./data/audible_auth.json
  auth_encryption: json           # Encrypted JSON format
# Environment variables
export AUDIBLE_AUTH_PASSWORD="your-secure-password"
export ABS_INSECURE_TLS=1  # DANGEROUS: disable SSL verification

πŸ§ͺ Development

Running Tests

make test              # Run all tests
make coverage          # With HTML coverage report
pytest -k "quality"    # Run specific tests
pytest -v --tb=short   # Verbose with short tracebacks

Code Quality

make format            # Black + isort
make lint              # flake8 + mypy + bandit
make pre-commit        # Run all pre-commit hooks

Pre-commit Hooks

make setup-hooks       # Install git hooks
make update-hooks      # Update to latest versions

Developer Utilities

Located in tools/:

Script Purpose
dev.py Make-like task runner for systems without make
dev_series_explore.py Series matching exploration/testing
python tools/dev.py help
python tools/dev_series_explore.py --library-id <id>

πŸ“ Project Structure

a2a/
β”œβ”€β”€ .github/              # GitHub Actions, templates, Dependabot
β”‚   β”œβ”€β”€ workflows/        # CI, release, pre-commit autoupdate
β”‚   └── ISSUE_TEMPLATE/   # Bug report, feature request forms
β”œβ”€β”€ src/                  # Source code modules
β”œβ”€β”€ tests/                # Pytest test suite (577+ tests)
β”œβ”€β”€ tools/                # Developer utilities
β”œβ”€β”€ docs/                 # Design docs, audit reports
β”œβ”€β”€ cli.py                # Main CLI entry point
β”œβ”€β”€ config.yaml.example   # Configuration template
β”œβ”€β”€ pyproject.toml        # Tool configuration (pytest, black, etc.)
└── Makefile              # Common development commands

🀝 Contributing

Contributions are welcome! Please read our guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Run tests and linting (make test && make lint)
  4. Commit with conventional commits (feat:, fix:, docs:)
  5. Push and open a Pull Request

See CONTRIBUTING.md for detailed guidelines and CODE_OF_CONDUCT.md for community standards.

πŸ“œ License

This project is licensed under the MIT License - see LICENSE for details.

⚠️ Note: This project uses the audible library which is licensed under AGPL-3.0. For personal CLI use, this has minimal impact. Review the license if distributing.

πŸ™ Acknowledgments

Audiobookshelf
Audiobookshelf
audible
audible
Typer
Typer
Rich
Rich

πŸ“ž Support

πŸ› Report Bug β€’ πŸ’‘ Request Feature β€’ πŸ“– Documentation


Made with ❀️ for audiobook enthusiasts

Star ⭐ this repo if you find it useful!

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages