Metadata-Version: 2.5
Name: clapclap-cli
Version: 0.2.2
Summary: CLAP CLI for Navidrome. Track radio, album radio, artist radio, automatic playlists generation, etc...
Project-URL: source, https://github.com/TheRaphael0000/clapclap
Project-URL: download, https://github.com/TheRaphael0000/clapclap/releases/latest
Project-URL: issues, https://github.com/TheRaphael0000/clapclap/issues
Keywords: audio-processing,audio-recommendation,clap,music-recommendation,navidrome-plugin,recommender-system
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
Requires-Python: >=3.13
Requires-Dist: alembic>=1.20.0
Requires-Dist: numpy>=2.5.3
Requires-Dist: pgvector>=0.5.0
Requires-Dist: platformdirs>=4.13.0
Requires-Dist: psycopg[binary]>=3.3.6
Requires-Dist: python-decouple>=3.8
Requires-Dist: sqlalchemy>=2.1.1
Requires-Dist: u-msgpack-python>=2.8.0
Provides-Extra: client
Requires-Dist: filetype>=1.2.0; extra == 'client'
Requires-Dist: requests>=2.34.2; extra == 'client'
Requires-Dist: scikit-learn>=1.9.1; extra == 'client'
Requires-Dist: scipy>=1.18.1; extra == 'client'
Requires-Dist: tinytag>=2.3.2; extra == 'client'
Requires-Dist: torch>=2.14.0; extra == 'client'
Requires-Dist: torchaudio>=2.11.0; extra == 'client'
Requires-Dist: torchcodec>=0.16.0; extra == 'client'
Requires-Dist: tqdm>=4.70.0; extra == 'client'
Requires-Dist: transformers>=5.17.0; extra == 'client'
Requires-Dist: umap-learn>=0.5.12; extra == 'client'
Provides-Extra: server
Requires-Dist: fastapi[standard]>=0.141.1; extra == 'server'
Requires-Dist: opendht>=4.4.1; extra == 'server'
Requires-Dist: uvicorn>=0.54.0; extra == 'server'
Description-Content-Type: text/markdown

# clapclap

clapclap is a python CLI for managing your CLAP embedding (Contrastive Language-Audio Pretraining).

It can be used as a song recommendation system for Navidrome.

> clapclap is build with the idea of working well with small and large databases

## Recommended setup with Navidrome

![schema clapclap setup with navidrome](https://raw.githubusercontent.com/TheRaphael0000/clapclap/refs/heads/main/doc/navidrome_setup_example.drawio.png)

## Install

The same python package can be installed in two modes:

- Server: Bare necessary to run the server, no optional dependencies
- Client: All dependencies, can compute new embeddings (includes: pytorch, transformers, etc...), require the '[all]' optional dependencies argument.

For the navidrome extension please refer to the clapclap_navidrome repository:
https://github.com/TheRaphael0000/clapclap_navidrome

### Install with PyPi (recommended for client)

```bash
# client (recommended)
pip install "clapclap-cli[client]"
clapclap --version

# server (not recommended, use docker instead)
pip install "clapclap-cli[server]"
clapclap --version
clapclap serve
```

### Install with Docker (recommended for server)

todo

### Install from GitHub release

```bash
WHL_URL=$(curl -s https://api.github.com/repos/TheRaphael0000/clapclap/releases/latest | jq -r '.assets[0].browser_download_url')
pip install "clapclap-cli[client,server] @ $WHL_URL"

# test installation
clapclap --version

# configure, see configuration section
vim ~/.config/clapclap/config.ini
```

Or get the latest wheel here: https://github.com/TheRaphael0000/clapclap/releases/latest

### Install from sources

```bash
# clone repository
git clone https://github.com/TheRaphael0000/clapclap.git
cd clapclap
# install with dev capabilities
pip install -e ".[client,server]" --group dev

# test installation
clapclap --version

# configure, see configuration section
vim ~/.config/clapclap/config.ini
```

## Configuration

Every configuration key value can either be set with environement variable when running the script (useful for docker for example). Or in a .ini configuration file.

Default configuration file location is: `~/.config/clapclap/config.ini` But it can be overwritten with the `--config`

config.ini should start with `[settings]`

| Key                       | Description                                                                                    | Default value          | Setup (Server or CLI) |
| ------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------- | --------------------- |
| POSTGRES_USER             | Username for the pgvector DB                                                                   | user                   | Both                  |
| POSTGRES_PASSWORD         | Password for the pgvector DB                                                                   | password               | Both                  |
| POSTGRES_DB               | clapclap database name in pgvector                                                             | clapclap               | Both                  |
| POSTGRES_HOST             | Hostname of the pgvector DB                                                                    | 127.0.0.1:5432         | Both                  |
| DATA_ROOT_DIR             | Path to the audio files, navidrome                                                             | /music/                | CLI                   |
| NAVIDROME_URL             | URL of your Navidrome instance                                                                 | http://127.0.0.1:4533/ | CLI                   |
| NAVIDROME_USER            | Navidrome account                                                                              | user                   | CLI                   |
| NAVIDROME_PASSWORD        | Navidrome password                                                                             | password               | CLI                   |
| NAVIDROME_ROOT_DIR        | Full path of your music directory on your navidrome server, needed to do exact path substition | /music/                | CLI                   |
| NAVIDROME_PLAYLIST_PREFIX | Optional prefix for all clapclap created playlists                                             | _empty_                | CLI                   |

### Example for clapclap CLI

```bash
# ~/.config/clapclap/config.ini
[settings]
POSTGRES_USER=clapclap
POSTGRES_PASSWORD=mydbpass1234
POSTGRES_DB=clapclap
POSTGRES_HOST=192.168.0.2:5432
DATA_ROOT_DIR=/mnt/samba/music/
NAVIDROME_URL=https://navi.example.com
NAVIDROME_USER=navi
NAVIDROME_PASSWORD=mynavipass1234
NAVIDROME_ROOT_DIR=/music/ # slash is important here
NAVIDROME_PLAYLIST_PREFIX=cc
```

## CLI

Commands examples, for the full list use `--help` with any subcommand

```bash
clapclap --help # list subcommands
clapclap update --help # work for any subcommand

# create the database
clapclap db --create

# update the clapclap database with the
clapclap update
# to download songs through navidrome API instead of network mount or local files
# clapclap update --navidrome

# query the database using the text strategy using "breakcore"
# limit it to 100 closest songs and save it to navidrome
clapclap query --save --limit 100 text "breakcore"

# start a clapclap server, not useful locally, must be run on the navidrome server, see
clapclap serve
```

### Example of an update script

```bash
#!/bin/bash
# run a navidrome scan in detached mode
clapclap navidrome scan --detach
# start updating your clapclap database, compute the clap embeddings
clapclap update
# wait for the scan previously started to finish
clapclap navidrome scan --wait
# update the clapclap database with IDs from navidrome, we assume that the new songs are within the 50 newest albums added to navidrome to have a faster matching
clapclap navidrome update --limit 50
```

### Example of a clustering script

```bash
#!/bin/zsh
# remove navidrome playlists starting with 'cc/'
clapclap navidrome playlist -r "cc/.*" -d
# create 300 playlists using kmeans on navidrome and with a prefix "cc/" will use "smart-naming" by default
clapclap clustering --prefix "cc/" kmeans -k 300
```