Metadata-Version: 2.4
Name: djai
Version: 0.3.0
Summary: Utilities for working with Django-based AI integrations.
Project-URL: Homepage, https://github.com/your-org/djai
Project-URL: Repository, https://github.com/your-org/djai
Project-URL: Issues, https://github.com/your-org/djai/issues
Author-email: Your Name <you@example.com>
License: MIT License
        
        Copyright (c) 2025 Will Sackfield
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: requests>=2.31.0
Requires-Dist: yt-dlp>=2024.10.22
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == 'dev'
Requires-Dist: ruff>=0.5.0; extra == 'dev'
Description-Content-Type: text/markdown

# djai

Tools for DJ ideation powered by AI/ML. The package ships with a command-line interface that helps you analyse your Spotify likes so you can feed curated metadata into downstream machine-learning workflows.

## Command Line Interface

Ensure you have a Spotify access token with the `user-library-read` scope. You can either pass it as a flag or export it as an environment variable:

```bash
export SPOTIFY_API_TOKEN="your-spotify-token"
djai --max-items 100 > liked_tracks.json
```

Key flags:

- `--token`: Provide the Spotify token directly (defaults to `SPOTIFY_API_TOKEN`).
- `--limit`: Batch size per API call (max 50; defaults to 50).
- `--max-items`: Optional cap on total tracks to fetch.

The CLI calls Spotify's `/v1/me/tracks` endpoint, caches responses, downloads MP3 previews via [`yt-dlp`](https://github.com/yt-dlp/yt-dlp) (requires `ffmpeg`), falling back to a YouTube search when Spotify doesn't expose a preview URL, and prints the total number of liked tracks retrieved.

### `.env` Support

Store secrets in a `.env` file to keep them out of your shell history:

```
SPOTIFY_CLIENT_ID="your-client-id"
SPOTIFY_CLIENT_SECRET="your-client-secret"
SPOTIFY_API_TOKEN="your-spotify-token"
```

The CLI automatically loads `.env` from the current working directory (or parent directories) using [`python-dotenv`](https://github.com/theskumar/python-dotenv). If an explicit API token is missing but client credentials are configured, `djai` launches a one-time Authorization Code flow using a temporary localhost listener to obtain fresh `access_token` and `refresh_token` values before fetching tracks. The resulting tokens are cached in `.djai_session` (ignored by git) so subsequent runs in the same directory reuse them. Downloaded previews are stored under `.djai_cache/audio`, and API responses are cached under `.djai_cache` for up to 30 days. Note that analysing a user's liked tracks still requires a token granted with the `user-library-read` scope.

## Development

```bash
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -e ".[dev]"
ruff check .
pytest
```

## Continuous Integration

GitHub Actions runs linting (`ruff`) and tests (`pytest`) on pushes and pull requests targeting `main` via `.github/workflows/ci.yml`.

## Publishing to PyPI

The manual **Publish** workflow in `.github/workflows/deploy.yml` builds and uploads the package. Before triggering it, bump the version in `pyproject.toml` and ensure a PyPI token is stored as `PYPI_API_TOKEN`.
