Skip to content

Commit deee265

Browse files
committed
feat(packaging): package project as abopus
Move the converter implementation into an installable package (src/abopus) and provide a CLI entry point with a compatibility shim (convert_audiobooks.py). Add pyproject.toml with package metadata to enable pip/pipx installation and wheel builds. Update Dockerfile to install the package and adjust workdir and entrypoint. Refresh README to document installation options and usage. Add a GitHub Actions workflow to publish tagged releases to PyPI.
1 parent d3543e6 commit deee265

8 files changed

Lines changed: 884 additions & 688 deletions

File tree

.github/workflows/pypi-publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
name: Build distribution
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.13"
21+
22+
- name: Install build tools
23+
run: pip install --upgrade build
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Upload distribution artifacts
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: dist
32+
path: dist/
33+
34+
publish-pypi:
35+
name: Publish to PyPI
36+
needs: build
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: pypi
40+
url: https://pypi.org/p/abopus
41+
permissions:
42+
id-token: write # Required for trusted publishing (OIDC)
43+
steps:
44+
- name: Download distribution artifacts
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: dist
48+
path: dist/
49+
50+
- name: Publish to PyPI
51+
uses: pypa/gh-action-pypi-publish@release/v1

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.13-alpine
22

3-
LABEL org.opencontainers.image.source="https://github.com/kadykov/audiobook-opus-converter"
3+
LABEL org.opencontainers.image.source="https://github.com/kadykov/abopus"
44
LABEL org.opencontainers.image.description="Audiobook to Opus converter — efficient batch conversion optimized for voice content"
55
LABEL org.opencontainers.image.licenses="MIT"
66

@@ -10,11 +10,13 @@ RUN apk add --no-cache \
1010
opus \
1111
imagemagick
1212

13-
# Copy the converter script
14-
COPY convert_audiobooks.py /app/convert_audiobooks.py
13+
# Install the Python package
14+
COPY pyproject.toml README.md LICENSE /app/
15+
COPY src/ /app/src/
16+
RUN pip install --no-cache-dir /app
1517

1618
# Set up volumes for input/output
1719
VOLUME ["/input", "/output"]
18-
WORKDIR /app
20+
WORKDIR /data
1921

20-
ENTRYPOINT ["python3", "convert_audiobooks.py", "-s", "/input", "-o", "/output"]
22+
ENTRYPOINT ["abopus", "-s", "/input", "-o", "/output"]

README.md

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Audiobook to Opus Converter
1+
# abopus — Audiobook to Opus Converter
22

3-
A Python tool that efficiently converts audiobooks to the [Opus format](https://opus-codec.org/), optimized for voice content. Achieves significant file size reduction while maintaining excellent audio quality, with automatic parallel processing using all CPU cores.
3+
A tool that efficiently converts audiobooks to the [Opus format](https://opus-codec.org/), optimized for voice content. Achieves significant file size reduction while maintaining excellent audio quality, with automatic parallel processing using all CPU cores.
44

55
## Features
66

@@ -15,16 +15,48 @@ A Python tool that efficiently converts audiobooks to the [Opus format](https://
1515

1616
## Quick Start
1717

18+
### Option 1: pipx / uvx (recommended)
19+
20+
No clone needed — just install and run:
21+
22+
```bash
23+
# Install with pipx (persistent install)
24+
pipx install abopus
25+
26+
# Or run directly with uvx (no install needed)
27+
uvx abopus -s ~/Audiobooks -o ~/Audiobooks_Opus
28+
```
29+
30+
> **Note:** FFmpeg must be installed on your system (`sudo apt install ffmpeg` / `brew install ffmpeg`).
31+
32+
### Option 2: Docker
33+
34+
Zero dependencies — only Docker required:
35+
36+
```bash
37+
docker run --rm \
38+
-v ./audiobooks:/input \
39+
-v ./output:/output \
40+
ghcr.io/kadykov/abopus
41+
42+
# With custom options
43+
docker run --rm \
44+
-v ./audiobooks:/input \
45+
-v ./output:/output \
46+
ghcr.io/kadykov/abopus -b 32k --stereo keep
47+
```
48+
49+
### Option 3: Run directly
50+
1851
```bash
1952
# Install dependencies
2053
sudo apt install ffmpeg python3 imagemagick # Ubuntu/Debian
2154
# or: brew install ffmpeg python3 imagemagick # macOS
2255

23-
# Convert audiobooks (uses all CPU cores, 24k bitrate by default)
56+
# Clone and run
57+
git clone https://github.com/kadykov/abopus.git
58+
cd abopus
2459
python3 convert_audiobooks.py
25-
26-
# Use lower bitrate for smaller files
27-
python3 convert_audiobooks.py -b 20k
2860
```
2961

3062
Input files: `./original/` → Output files: `./opus/`
@@ -35,25 +67,25 @@ Input files: `./original/` → Output files: `./opus/`
3567

3668
```bash
3769
# Convert with defaults (all CPU cores, 24k bitrate, downmix stereo to mono)
38-
python3 convert_audiobooks.py
70+
abopus
3971

4072
# Custom directories
41-
python3 convert_audiobooks.py -s ~/Audiobooks -o ~/Audiobooks_Opus
73+
abopus -s ~/Audiobooks -o ~/Audiobooks_Opus
4274

4375
# Specific number of workers
44-
python3 convert_audiobooks.py -w 4
76+
abopus -w 4
4577

4678
# High quality
47-
python3 convert_audiobooks.py -b 32k
79+
abopus -b 32k
4880

4981
# Keep stereo files as stereo
50-
python3 convert_audiobooks.py --stereo keep
82+
abopus --stereo keep
5183

5284
# Increase bitrate for stereo files (32k)
53-
python3 convert_audiobooks.py --stereo increase-bitrate
85+
abopus --stereo increase-bitrate
5486

5587
# Verbose output
56-
python3 convert_audiobooks.py -v
88+
abopus -v
5789
```
5890

5991
### Options
@@ -147,15 +179,15 @@ The script provides three strategies for handling multi-channel audio:
147179
Converts stereo to mono, preserving more bitrate for voice clarity. Best for audiobooks where narration is the primary focus.
148180

149181
```bash
150-
python3 convert_audiobooks.py --stereo downmix
182+
abopus --stereo downmix
151183
```
152184

153185
### keep
154186

155187
Keeps stereo files as-is. At lower bitrates (e.g., 24k or below), Opus may partially downmix stereo anyway.
156188

157189
```bash
158-
python3 convert_audiobooks.py --stereo keep
190+
abopus --stereo keep
159191
```
160192

161193
### increase-bitrate
@@ -169,7 +201,7 @@ Automatically increases bitrate for stereo files by 60% to preserve stereo imagi
169201
- 40k → 64k
170202

171203
```bash
172-
python3 convert_audiobooks.py --stereo increase-bitrate
204+
abopus --stereo increase-bitrate
173205
```
174206

175207
## Technical Details
@@ -201,17 +233,14 @@ python3 convert_audiobooks.py --stereo increase-bitrate
201233

202234
```bash
203235
# Check dependencies
204-
python3 --version # Should be 3.7+
236+
abopus --help # Should print help
205237
ffmpeg -version # Should be installed
206238

207239
# Verify Opus support
208240
ffmpeg -codecs | grep opus
209241

210-
# Make script executable
211-
chmod +x convert_audiobooks.py
212-
213242
# Run with verbose output
214-
python3 convert_audiobooks.py -v
243+
abopus -v
215244
```
216245

217246
## How It Works
@@ -229,20 +258,61 @@ python3 convert_audiobooks.py -v
229258
## Project Structure
230259

231260
```plain
232-
audiobook-opus-converter/
233-
├── convert_audiobooks.py # Main script
261+
abopus/
262+
├── src/abopus/ # Python package
263+
│ ├── __init__.py # Version
264+
│ ├── __main__.py # python -m abopus entry point
265+
│ └── converter.py # Conversion logic
266+
├── convert_audiobooks.py # Compatibility shim
267+
├── pyproject.toml # Package metadata
268+
├── Dockerfile # Docker image
234269
├── README.md # Documentation
235-
├── original/ # Place source files here
270+
├── original/ # Place source files here (default)
236271
│ └── Book Name/
237272
│ └── chapter01.mp3
238273
└── opus/ # Converted files (auto-created)
239274
└── Book Name/
240275
└── chapter01.opus
241276
```
242277

278+
## Installation
279+
280+
### pipx / uvx (recommended)
281+
282+
```bash
283+
# Persistent install
284+
pipx install abopus
285+
286+
# Or run without installing
287+
uvx abopus --help
288+
```
289+
290+
### Docker
291+
292+
```bash
293+
docker run --rm \
294+
-v ./audiobooks:/input \
295+
-v ./output:/output \
296+
ghcr.io/kadykov/abopus
297+
```
298+
299+
### pip
300+
301+
```bash
302+
pip install abopus
303+
```
304+
305+
### From source
306+
307+
```bash
308+
git clone https://github.com/kadykov/abopus.git
309+
cd abopus
310+
pip install -e .
311+
```
312+
243313
## Requirements
244314

245-
**Required:**
315+
**Required (except Docker — everything is included):**
246316

247317
- Python 3.7 or later
248318
- FFmpeg with libopus support
@@ -253,14 +323,14 @@ audiobook-opus-converter/
253323

254324
```bash
255325
# Ubuntu/Debian
256-
sudo apt install ffmpeg python3 imagemagick
326+
sudo apt install ffmpeg imagemagick
257327

258328
# Fedora
259-
sudo dnf install ffmpeg python3 ImageMagick
329+
sudo dnf install ffmpeg ImageMagick
260330

261331
# Arch Linux
262-
sudo pacman -S ffmpeg python3 imagemagick
332+
sudo pacman -S ffmpeg imagemagick
263333

264334
# macOS
265-
brew install ffmpeg python3 imagemagick
335+
brew install ffmpeg imagemagick
266336
```

0 commit comments

Comments
 (0)