Skip to main content

librofm

A Python client library for syncing your audiobooks from Libro.fm.

Features

  • Download audiobooks from your Libro.fm library
  • Support for both MP3 and M4B formats (M4B preferred when available)
  • Automatic, configurable file organization
  • Command-line interface for syncing your audiobooks locally
  • Python API for programmatic access

Installation

pip install librofm

Configuration

In order for this to work at all, you have to set your Libro.fm credentials as environment variables:

export LIBROFM_USERNAME="your_username"
export LIBROFM_PASSWORD="your_password"

Alternatively, create an environment file. It will search in the following order:

  • ./.librofm
  • ./.env
  • ~/.librofm

If running from the commandline, you can specify a specific file to use with --config <file>.

The two other configuration options are:

  • LIBROFM_OUTPUT_DIR: The base directory in which to store you downloads. Defaults to ~/Audiobooks
  • LIBROFM_DESTINATION_PATTERN: How you want your files organized. Defaults to < authors >/< title >

Note: It's authors, plural. You can use any field in the Audiobook model, as well as any other text.

Usage

Command Line

Download all audiobooks to the default directory (~/Audiobooks):

librofm-sync

Download to a custom directory, overriding .env:

librofm-sync --base-path /path/to/audiobooks

By default, it won't download books it has previously retrieved. You can force it to redownload:

librofm-sync --force

You probably want to include --overyouwrite with --force. They are separate because, since you can configure the destination however you want, there's extra safety so you don't accidentally overwrite a book if you, for example, dump everything into a single folder.

If you've previously downloaded books, you can have librofm-sync try to match them with the books in your LibroFM library. You may want to adjust destination_pattern setting to match how you've organized things (The default is <authors>/<title>).

librofm-sync --create-index

Show help:

librofm-sync --help

Python API

from librofm.client import LibroFMClient

# Create client (uses environment variables)
client = LibroFMClient.get_client()

# Or create with explicit settings
client = LibroFMClient("username", "password", "~/Audiobooks", "< authors >/< title>")

# Get your library
audiobooks = client.get_library()
print(f"Found {len(audiobooks)} audiobooks")

# Download a specific audiobook
audiobook = audiobooks[0]
success = client.download(audiobook)

# Get download manifest for MP3 files
manifest = client.get_download_manifest(audiobook)
print(f"Audiobook has {len(manifest.parts)} parts")

# Get M4B package info
m4b_info = client.get_packaged_m4b_info(audiobook)
if m4b_info:
    print(f"M4B available at: {m4b_info.m4b_url}")

File Organization

By default, downloaded audiobooks are organized as:

base_path/
    Author Name/
        Book Title/
            part1.mp3
            part2.mp3
            ...
    Another Author/
        Another Book/
            book.m4b

This default configuration looks like: < authors >/< title >. If you want to put all books by an author into the same folder, you would use <authors>.

You can add anything that is in the Audiobook model. I don't know why you'd want to, but you can do strange things like < authors >/< isbn >/banana.

Duplicate Detection

When a book is downlaoded, librofm-sync creates a file in the directory that contains LibroFM ID of that book. When you perform another sync, it will find all the index files in the output directory and (unless you use --force) it will skip books previously downloaded. Using the index files instead of, for example, the destination directory, means you can move and rename files as you wish. As long as you leave the index file in place, it will be detected and future syncs will not duplicate the work.

I did not come up with this idea. It's similar to the pattern used in BandcampSync and I adapted it here.It's much better than what I had originally intended.

Requirements

  • Python 3.10+
  • Active Libro.fm account with audiobooks in your library

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

This tool is not associated with LibroFM in any way.

This tool is for personal use only. Please respect Libro.fm's terms of service and only download audiobooks you have legally purchased.

Release files for librofm 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for librofm 1.1.0
File Size Uploaded
librofm-1.1.0.tar.gz 22.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for librofm 1.1.0
File Interpreter ABI Platform
librofm-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size:45.6 kB

Release files / librofm-1.1.0.tar.gz

Download URL librofm-1.1.0.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aedf80bb072f0e39ca3c876978d27896a0387d4ee68c9c614c4dfb6090bfe32e
BLAKE2b-256 checksum
How to use checksums
4e0df70440e0bdda4515b84c5a01d9b8ee48bb4d9bf9984485bc0ee635b21627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.6 Linux/6.18.48-gentoo-dist-bin

Release files / librofm-1.1.0-py3-none-any.whl

Download URL librofm-1.1.0-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
443b0db17e38c3b63f1bca672d78dcde742bb1967393e973d8fedf502269489a
BLAKE2b-256 checksum
How to use checksums
4eeb4e2c0d18facbbb1bf6a1a25cd8722fcc32e801f08d011dd2ca45cd867b78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.6 Linux/6.18.48-gentoo-dist-bin

Release history Release notifications | RSS feed

1.1.1

2 release files

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page