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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

librofm-1.1.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

librofm-1.1.1-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file librofm-1.1.1.tar.gz.

File metadata

  • Download URL: librofm-1.1.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.3 CPython/3.14.6 Linux/6.18.48-gentoo-dist-bin

File hashes

Hashes for librofm-1.1.1.tar.gz
Algorithm Hash digest
SHA256 bc6f3d1c37d35e43a48590b82ec029b809a71c4041b9cb37fdfa6355c0f99e9e
MD5 ea882aaeb1c35adba67d4962cead8d74
BLAKE2b-256 71f6c6cb4c57b35b555946d99845d9e10061aa3bf1333c8d260267759ca8e33f

See more details on using hashes here.

File details

Details for the file librofm-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: librofm-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.3 CPython/3.14.6 Linux/6.18.48-gentoo-dist-bin

File hashes

Hashes for librofm-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8fcc8b51ec98c2739b8e972617f80d074cb367ededfea62ebbe1157031c03ccb
MD5 8e8b5ff15e1c4535684f383204502c3b
BLAKE2b-256 013a5cf213c123bf51ea02ed40da4279018a2c803c1373b235b10cfc577f5e37

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.0

2 files

0.2.0

2 files

0.1.0

2 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