Metadata-Version: 2.2
Name: dakarafeeder
Version: 1.9.0
Summary: External database feeder for the Dakara Project
Author-email: Flore <flore.love@gmail.com>, Neraste <neraste.herr10@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Dakara Project
        
        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.
        
Project-URL: Homepage, https://github.com/DakaraProject/dakara-feeder
Project-URL: Repository, https://github.com/DakaraProject/dakara-feeder.git
Project-URL: Issues, https://github.com/DakaraProject/dakara-feeder/issues
Project-URL: Changelog, https://github.com/DakaraProject/dakara-feeder/blob/master/CHANGELOG.md
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
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
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: dakarabase<2.2.0,>=2.1.0
Requires-Dist: filetype<1.3.0,>=1.2.0
Requires-Dist: packaging<25.0,>=24.2
Requires-Dist: pymediainfo<7.1.0,>=7.0.1
Requires-Dist: pysubs2<1.9.0,>=1.8.0
Provides-Extra: dev
Requires-Dist: black<25.2.0,>=25.1.0; extra == "dev"
Requires-Dist: codecov<2.2.0,>=2.1.13; extra == "dev"
Requires-Dist: isort<6.1.0,>=6.0.0; extra == "dev"
Requires-Dist: pdoc<15.2.0,>=15.0.1; extra == "dev"
Requires-Dist: pre-commit<4.2.0,>=4.1.0; extra == "dev"
Requires-Dist: pytest-cov<6.1.0,>=6.0.0; extra == "dev"
Requires-Dist: pytest<8.4.0,>=8.3.4; extra == "dev"
Requires-Dist: ruff<0.10.0,>=0.9.6; extra == "dev"

# Dakara Feeder

<!-- Badges are displayed for the develop branch -->
[![PyPI version](https://badge.fury.io/py/dakarafeeder.svg)](https://pypi.python.org/pypi/dakarafeeder/)
[![PyPI Python versions](https://img.shields.io/pypi/pyversions/dakarafeeder.svg)](https://pypi.python.org/pypi/dakarafeeder/)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.python.org/pypi/dakarafeeder/)
[![Tests status](https://github.com/DakaraProject/dakara-feeder/actions/workflows/ci.yml/badge.svg)](https://github.com/DakaraProject/dakara-feeder/actions/workflows/ci.yml)
[![Code coverage status](https://codecov.io/gh/DakaraProject/dakara-feeder/branch/develop/graph/badge.svg)](https://codecov.io/gh/DakaraProject/dakara-feeder)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

Allows to feed the database of the Dakara server remotely.

## Installation

This repo is tied with the Dakara server, so you should setup it first:

* [Dakara server](https://github.com/DakaraProject/dakara-server/).

Other important parts of the project include:

* [Dakara VLC player](https://github.com/DakaraProject/dakara-player-vlc/).

### System requirements

* Python3, to make everything up and running (supported versions: see above);
* [ffmpeg](https://www.ffmpeg.org/), to extract lyrics and extract metadata from files (preferred way);
* [MediaInfo](https://mediaarea.net/fr/MediaInfo/), to extract metadata from files (slower, alternative way).

Linux, Windows, and MacOS are supported.

### Virtual environment

It is strongly recommended to use the Dakara feeder within a virtual environment.

### Install

Please ensure you have a recent enough version of `setuptools`:

```sh
pip install --upgrade "setuptools>=46.4.0"
```

Install the package with:

```sh
pip install dakarafeeder
```

If you have downloaded the repo, you can install the package directly with:

```sh
pip install .
```

## Usage

### Commands

The package provides the `dakara-feeder feed` command for creating data on a running instance of the Dakara server.
Several sub-commands are available.
To begin, `dakara-feeder feed songs` will find songs in the configured directory, parse them and send their data:

```sh
dakara-feeder feed songs
# or
python -m dakara_feeder feed songs
```

One instance of the Dakara server should be running.

The data extracted from songs are very limited in this package by default, as data can be stored in various ways. You are encouraged to make your own parser (see [this section](#making-a-custom-parser) for more details).

Then, `dakara-feeder feed tags` and `dakara-feeder feed work-types` will find tags and work types in a YAML file (see [this section](#tags-and-work-types-file) for more details):

```sh
dakara-feeder feed tags path/to/tags.yaml
# or
python -m dakara_feeder feed tags path/to/tags.yaml
```

and:

```sh
dakara-feeder feed work-types path/to/work_types.yaml
# or
python -m dakara_feeder feed work-types path/to/work_types.yaml
```

Also, `dakara-feeder feed works` will find works in a JSON file (see [this section](#works-file) for more details):

```sh
dakara-feeder feed works path/to/works.json
# or
python -m dakara_feeder feed works path/to/works.json
```

For more help:

```sh
dakara-feeder -h
# or
python -m dakara_feeder -h
```

Before calling any command, you should create a config file with:

```sh
dakara-feeder create-config
# or
python -m dakara_feeder create-config
```

and complete it with your values. The file is stored in your user space: `~/.config/dakara` on Linux, or `$APPDATA\DakaraProject\dakara` on Windows.

### Configuration

The configuration is created with the previously cited command. Several aspect of the feeder can be configured with this file. Please check with the file documentation.

Authentication to the server can be done with username and password, or with a token that can be copied from the web client. Please note that only a library manager can use the feeder.

### Making a custom parser

To override the extraction of data from song files, you should create a class derived from `dakara_feeder.song.BaseSong`. Please refer to the documentation of this class to learn which methods to override, and what attributes and helpers are at your disposal.

Here is a basic example. It considers that the song video file is formatted in the way "title - main artist.ext":

```python
# my_song.py
from dakara_feeder.song import BaseSong

class Song(BaseSong):
    def get_title(self):
        return self.video_path.stem.split(" - ")[0]

    def get_artists(self):
        return [{"name": self.video_path.stem.split(" - ")[1]}]
```

To register your customized `Song` class, you simply indicate it in the configuration file.
You can either indicate an importable module or a file:

```yaml
custom_song_class: path/to/my_song.py::Song
# or
custom_song_class: my_song.Song
```

Now, `dakara-feeder` will use your customized `Song` class instead of the default one.

### Tags and work types file

Whilst data from songs are extracted directly from song files, data from tags and work types are extracted from a YAML file.
All data can coexist in the same file.

#### Tags

Tags will be searched in the key `tags`.
Tags are identified by their name (it will be displayed in upper case, it
should be just one word).
You can provide a color hue (positive integer from 0 to 360):

```yaml
tags:
  - name: PV
    color_hue: 162
  - name: AMV
    color_hue: 140
```

#### Work types

Work types will be searched in the key `worktypes`
Work types are identified by their query name (hyphenated name, with no special
characters, used as keyword for querying).
You can provide a work type display name (singular and plural) and an icon name (choosen among the
[FontAwesome](http://fontawesome.io/icons/) font glyphes):

```yaml
worktypes:
  - query_name: anime
    name: Anime
    name_plural: Animes
    icon_name: television
  - query_name: live-action
    name: Live action
    name_plural: Live actions
    icon_name: film
```

### Works file

You can provide more information about works (especially alternative names) from a JSON file.
The file should contain a dictionary where keys are work types query name and values lists of works representation:

```json
{
  "work_type_1":
    [
      {
        "title": "Work 1",
        "subtitle": "Subtitle 1",
        "alternative_titles": [
          {
            "title": "AltTitle 1"
          },
          {
            "title": "AltTitle 2"
          }
        ]
      },
      {
        "title": "Work 2",
        "subtitle": "Subtitle 2"
      }
    ],
  "work_type_2": []
}
```

Identification with existing works on the server is made with the work type, the title and the subtitle, case insensitively.

## Development

Please read the [developers documentation](CONTRIBUTING.md).
