audiolibrarian 0.17.0__tar.gz → 0.18.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/.gitignore +1 -2
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/PKG-INFO +1 -1
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/api/audiolibrarian.md +1 -1
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/user-guide/changelog.md +11 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/user-guide/configuration.md +21 -19
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/pyproject.toml +3 -1
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/__init__.py +1 -1
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiosource.py +3 -4
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/base.py +17 -66
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/commands.py +58 -17
- audiolibrarian-0.17.0/src/audiolibrarian/settings.py → audiolibrarian-0.18.0/src/audiolibrarian/config.py +53 -15
- audiolibrarian-0.18.0/src/audiolibrarian/entrypoints/__init__.py +17 -0
- {audiolibrarian-0.17.0/src/audiolibrarian → audiolibrarian-0.18.0/src/audiolibrarian/entrypoints}/cli.py +2 -2
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/genremanager.py +5 -5
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/musicbrainz.py +27 -13
- audiolibrarian-0.18.0/src/audiolibrarian/normalizer.py +155 -0
- audiolibrarian-0.18.0/src/audiolibrarian/templates/config.toml +36 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/uv.lock +48 -34
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/.github/workflows/main.yml +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/.python-version +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/.readthedocs.yaml +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/CONTRIBUTING.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/COPYING +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/LICENSE +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/Makefile +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/README.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/development/contributing.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/index.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/user-guide/advanced.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/user-guide/getting-started.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/docs/user-guide/installation.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/git_hooks/README.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/git_hooks/pre-push +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/mkdocs.yml +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/scripts/update_links.sh +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/__init__.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/audiofile.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/formats/__init__.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/formats/flac.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/formats/m4a.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/formats/mp3.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/audiofile/tags.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/output.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/records.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/sh.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/audiolibrarian/text.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/picard_src/README.md +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/picard_src/__init__.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/src/picard_src/textencoding.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/tools/__init__.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/tools/diff.py +0 -0
- {audiolibrarian-0.17.0 → audiolibrarian-0.18.0}/tools/show_tags.py +0 -0
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.18.0] - 2025-06-27
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- New `config` command to view and manage configuration
|
13
|
+
- Support for tilde (`~`) in configuration file paths
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Switched from YAML to TOML for configuration files
|
18
|
+
|
8
19
|
## [0.17.0] - 2025-06-22
|
9
20
|
|
10
21
|
### Added
|
@@ -20,35 +20,37 @@ export AUDIOLIBRARIAN__MUSICBRAINZ__USERNAME="your_username"
|
|
20
20
|
export AUDIOLIBRARIAN__MUSICBRAINZ__PASSWORD="your_password"
|
21
21
|
```
|
22
22
|
|
23
|
-
### 2.
|
23
|
+
### 2. TOML Configuration File (medium precedence)
|
24
24
|
|
25
|
-
- **Default location**: `~/.config/audiolibrarian/config.
|
25
|
+
- **Default location**: `~/.config/audiolibrarian/config.toml`
|
26
26
|
- **Example**:
|
27
27
|
|
28
|
-
```
|
28
|
+
```toml
|
29
29
|
# Base directory for your music library
|
30
|
-
library_dir
|
30
|
+
library_dir = "~/music/library"
|
31
31
|
|
32
32
|
# Cache and working directory
|
33
|
-
work_dir
|
33
|
+
work_dir = "~/.cache/audiolibrarian"
|
34
34
|
|
35
|
-
# CD/DVD device path (use
|
36
|
-
discid_device
|
35
|
+
# CD/DVD device path (use empty string for default device)
|
36
|
+
discid_device = ""
|
37
37
|
|
38
38
|
# Audio normalization settings
|
39
|
-
normalize
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
[normalize]
|
40
|
+
normalizer = "auto" # "auto", "wavegain", "ffmpeg", or "none"
|
41
|
+
|
42
|
+
[normalize.ffmpeg]
|
43
|
+
target_level = -13 # Target LUFS level for ffmpeg normalization
|
44
|
+
|
45
|
+
[normalize.wavegain]
|
46
|
+
gain = 5 # dB gain for wavegain normalization (0-10)
|
47
|
+
preset = "radio" # "album" or "radio"
|
46
48
|
|
47
49
|
# MusicBrainz API settings (optional)
|
48
|
-
musicbrainz
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
[musicbrainz]
|
51
|
+
username = "your_username" # For personal genre preferences
|
52
|
+
password = "your_password" # Will be stored securely
|
53
|
+
rate_limit = 1.5 # Seconds between API requests
|
52
54
|
```
|
53
55
|
|
54
56
|
### 3. Default Values (lowest precedence)
|
@@ -61,7 +63,7 @@ musicbrainz:
|
|
61
63
|
|---------------------------------|------------------|-------------------------------------------|
|
62
64
|
| `library_dir` | `./library` | Directory for storing audio files |
|
63
65
|
| `work_dir` | (see below)[^wd] | Directory for temporary files |
|
64
|
-
| `discid_device` |
|
66
|
+
| `discid_device` | `` | CD device path (null for default device) |
|
65
67
|
| `normalize.normalizer` | `"auto"` | "auto", "wavegain", "ffmpeg", or "none" |
|
66
68
|
| `normalize.ffmpeg.target_level` | `-13` | Target LUFS level (ffmpeg) |
|
67
69
|
| `normalize.wavegain.gain` | `5` | Normalization gain in dB (0-10, wavegain) |
|
@@ -13,6 +13,7 @@ dev = [
|
|
13
13
|
"pymarkdownlnt",
|
14
14
|
"pytest",
|
15
15
|
"pytest-env",
|
16
|
+
"pytest-mock",
|
16
17
|
"ruff",
|
17
18
|
"types-pyyaml",
|
18
19
|
"types-requests",
|
@@ -49,7 +50,7 @@ readme = "README.md"
|
|
49
50
|
requires-python = ">=3.12,<3.14"
|
50
51
|
|
51
52
|
[project.scripts]
|
52
|
-
audiolibrarian = "audiolibrarian:
|
53
|
+
audiolibrarian = "audiolibrarian.entrypoints.cli:main"
|
53
54
|
|
54
55
|
[project.urls]
|
55
56
|
Repository = "https://github.com/toadstule/audiolibrarian"
|
@@ -86,6 +87,7 @@ ignore_errors = true # This is not our code.
|
|
86
87
|
[tool.pymarkdown]
|
87
88
|
plugins.md013.line_length = 100
|
88
89
|
plugins.md013.code_block_line_length = 100
|
90
|
+
plugins.md024.enabled = false
|
89
91
|
#plugins.md007.enabled = true
|
90
92
|
#plugins.md007.code_block_line_length = 160
|
91
93
|
|
@@ -27,8 +27,7 @@ from collections.abc import Callable # noqa: TC003
|
|
27
27
|
|
28
28
|
import discid
|
29
29
|
|
30
|
-
from audiolibrarian import audiofile, records, sh, text
|
31
|
-
from audiolibrarian.settings import SETTINGS
|
30
|
+
from audiolibrarian import audiofile, config, records, sh, text
|
32
31
|
|
33
32
|
log = logging.getLogger(__name__)
|
34
33
|
|
@@ -93,10 +92,10 @@ class AudioSource(abc.ABC):
|
|
93
92
|
class CDAudioSource(AudioSource):
|
94
93
|
"""AudioSource from a compact disc."""
|
95
94
|
|
96
|
-
def __init__(self) -> None:
|
95
|
+
def __init__(self, settings: config.Settings) -> None:
|
97
96
|
"""Initialize a CDAudioSource."""
|
98
97
|
super().__init__()
|
99
|
-
self._cd = discid.read(
|
98
|
+
self._cd = discid.read(settings.discid_device or None, features=["mcn"])
|
100
99
|
|
101
100
|
def get_search_data(self) -> dict[str, str]:
|
102
101
|
"""Return a dictionary of search data useful for doing a MusicBrainz search."""
|
@@ -23,19 +23,25 @@ import argparse
|
|
23
23
|
import logging
|
24
24
|
import pathlib
|
25
25
|
import shutil
|
26
|
-
import subprocess
|
27
26
|
import sys
|
28
27
|
import warnings
|
29
28
|
from collections.abc import Iterable
|
30
29
|
from typing import Any, Final
|
31
30
|
|
32
31
|
import colors
|
33
|
-
import ffmpeg_normalize
|
34
32
|
import filelock
|
35
33
|
import yaml
|
36
34
|
|
37
|
-
from audiolibrarian import
|
38
|
-
|
35
|
+
from audiolibrarian import (
|
36
|
+
audiofile,
|
37
|
+
audiosource,
|
38
|
+
config,
|
39
|
+
musicbrainz,
|
40
|
+
normalizer,
|
41
|
+
records,
|
42
|
+
sh,
|
43
|
+
text,
|
44
|
+
)
|
39
45
|
|
40
46
|
log = logging.getLogger(__name__)
|
41
47
|
|
@@ -49,8 +55,9 @@ class Base:
|
|
49
55
|
command: str | None = None
|
50
56
|
_manifest_file: Final[str] = "Manifest.yaml"
|
51
57
|
|
52
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
58
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
53
59
|
"""Initialize the base."""
|
60
|
+
self._settings = settings
|
54
61
|
# Pull in stuff from args.
|
55
62
|
search_keys = ("album", "artist", "mb_artist_id", "mb_release_id")
|
56
63
|
self._provided_search_data = {k: v for k, v in vars(args).items() if k in search_keys}
|
@@ -60,8 +67,8 @@ class Base:
|
|
60
67
|
self._disc_number, self._disc_count = 1, 1
|
61
68
|
|
62
69
|
# Directories.
|
63
|
-
self._library_dir =
|
64
|
-
self._work_dir =
|
70
|
+
self._library_dir = self._settings.library_dir
|
71
|
+
self._work_dir = self._settings.work_dir
|
65
72
|
self._flac_dir = self._work_dir / "flac"
|
66
73
|
self._m4a_dir = self._work_dir / "m4a"
|
67
74
|
self._mp3_dir = self._work_dir / "mp3"
|
@@ -70,7 +77,7 @@ class Base:
|
|
70
77
|
|
71
78
|
self._lock = filelock.FileLock(str(self._work_dir) + ".lock")
|
72
79
|
|
73
|
-
self._normalizer = self.
|
80
|
+
self._normalizer = normalizer.Normalizer.factory(self._settings.normalize)
|
74
81
|
|
75
82
|
# Initialize stuff that will be defined later.
|
76
83
|
self._audio_source: audiosource.AudioSource | None = None
|
@@ -143,7 +150,7 @@ class Base:
|
|
143
150
|
search_data: dict[str, str] = (
|
144
151
|
self._audio_source.get_search_data() if self._audio_source is not None else {}
|
145
152
|
)
|
146
|
-
searcher = musicbrainz.Searcher(**search_data) # type: ignore[arg-type]
|
153
|
+
searcher = musicbrainz.Searcher(settings=self._settings.musicbrainz, **search_data) # type: ignore[arg-type]
|
147
154
|
searcher.disc_number = str(self._disc_number)
|
148
155
|
# Override with user-provided info.
|
149
156
|
if value := self._provided_search_data.get("artist"):
|
@@ -269,35 +276,7 @@ class Base:
|
|
269
276
|
|
270
277
|
def _normalize(self) -> None:
|
271
278
|
"""Normalize the wav files using the selected normalizer."""
|
272
|
-
|
273
|
-
return
|
274
|
-
print(f"Normalizing wav files using {self._normalizer}...")
|
275
|
-
|
276
|
-
if self._normalizer == "wavegain":
|
277
|
-
command = [
|
278
|
-
"wavegain",
|
279
|
-
f"--{SETTINGS.normalize.wavegain.preset}",
|
280
|
-
f"--gain={SETTINGS.normalize.wavegain.gain}",
|
281
|
-
"--apply",
|
282
|
-
]
|
283
|
-
command.extend(str(f) for f in self._wav_filenames)
|
284
|
-
result = subprocess.run(command, capture_output=True, check=False) # noqa: S603
|
285
|
-
for line in str(result.stderr).split(r"\n"):
|
286
|
-
line_trunc = line[:137] + "..." if len(line) > 140 else line # noqa: PLR2004
|
287
|
-
log.info("WAVEGAIN: %s", line_trunc)
|
288
|
-
result.check_returncode()
|
289
|
-
return
|
290
|
-
|
291
|
-
normalizer = ffmpeg_normalize.FFmpegNormalize(
|
292
|
-
extension="wav",
|
293
|
-
keep_loudness_range_target=True,
|
294
|
-
target_level=SETTINGS.normalize.ffmpeg.target_level,
|
295
|
-
)
|
296
|
-
for wav_file in self._wav_filenames:
|
297
|
-
normalizer.add_media_file(str(wav_file), str(wav_file))
|
298
|
-
log.info("NORMALIZER: starting ffmpeg normalization...")
|
299
|
-
normalizer.run_normalization()
|
300
|
-
log.info("NORMALIZER: ffmpeg normalization completed successfully")
|
279
|
+
self._normalizer.normalize(set(self._wav_filenames))
|
301
280
|
|
302
281
|
def _rename_wav(self) -> None:
|
303
282
|
"""Rename the wav files to a filename-sane representation of the track title."""
|
@@ -428,34 +407,6 @@ class Base:
|
|
428
407
|
yaml.dump(manifest, manifest_file)
|
429
408
|
print(f"Wrote {manifest_filename}")
|
430
409
|
|
431
|
-
@staticmethod
|
432
|
-
def _which_normalizer() -> str:
|
433
|
-
"""Determine which normalizer to use based on settings and availability.
|
434
|
-
|
435
|
-
Returns:
|
436
|
-
str: The name of the normalizer to use ("wavegain", "ffmpeg" or "none")
|
437
|
-
"""
|
438
|
-
normalizer = SETTINGS.normalize.normalizer
|
439
|
-
if normalizer == "none":
|
440
|
-
return "none"
|
441
|
-
|
442
|
-
wavegain_found = shutil.which("wavegain")
|
443
|
-
if normalizer in ("auto", "wavegain") and wavegain_found:
|
444
|
-
return "wavegain"
|
445
|
-
|
446
|
-
ffmpeg_found = shutil.which("ffmpeg")
|
447
|
-
if normalizer in ("auto", "ffmpeg") and ffmpeg_found:
|
448
|
-
return "ffmpeg"
|
449
|
-
|
450
|
-
if wavegain_found:
|
451
|
-
log.warning("ffmpeg not found, using wavegain for normalization")
|
452
|
-
return "wavegain"
|
453
|
-
if ffmpeg_found:
|
454
|
-
log.warning("wavegain not found, using ffmpeg for normalization")
|
455
|
-
return "ffmpeg"
|
456
|
-
log.warning("wavegain not found, ffmpeg not found, using no normalization")
|
457
|
-
return "none"
|
458
|
-
|
459
410
|
@staticmethod
|
460
411
|
def _find_audio_files(directories: list[str | pathlib.Path]) -> Iterable[audiofile.AudioFile]:
|
461
412
|
"""Yield audiofile objects found in the given directories."""
|
@@ -22,7 +22,7 @@ import pathlib
|
|
22
22
|
import re
|
23
23
|
from typing import Any
|
24
24
|
|
25
|
-
from audiolibrarian import __version__, audiofile, audiosource, base, genremanager
|
25
|
+
from audiolibrarian import __version__, audiofile, audiosource, base, config, genremanager
|
26
26
|
|
27
27
|
log = logging.getLogger(__name__)
|
28
28
|
|
@@ -39,6 +39,46 @@ class _Command:
|
|
39
39
|
return True
|
40
40
|
|
41
41
|
|
42
|
+
class Config(_Command, base.Base):
|
43
|
+
"""AudioLibrarian tool for working with a config file.
|
44
|
+
|
45
|
+
This class performs all of its tasks on instantiation and provides no public members or
|
46
|
+
methods.
|
47
|
+
"""
|
48
|
+
|
49
|
+
command = "config"
|
50
|
+
help = "work with the config file"
|
51
|
+
parser = argparse.ArgumentParser(description="Manage AudioLibrarian configuration")
|
52
|
+
parser.add_argument(
|
53
|
+
"--init",
|
54
|
+
"-i",
|
55
|
+
action="store_true",
|
56
|
+
help="initialize a new config file if it doesn't exist",
|
57
|
+
)
|
58
|
+
|
59
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
60
|
+
"""Initialize a Config command handler."""
|
61
|
+
super().__init__(args, settings)
|
62
|
+
|
63
|
+
if args.init:
|
64
|
+
try:
|
65
|
+
config.init_config_file()
|
66
|
+
except FileExistsError as e:
|
67
|
+
msg = f"Config file already exists at {config.CONFIG_PATH}"
|
68
|
+
raise SystemExit(msg) from e
|
69
|
+
except Exception:
|
70
|
+
log.exception("Error creating config file")
|
71
|
+
raise
|
72
|
+
print(f"Created new config file at {config.CONFIG_PATH}")
|
73
|
+
else:
|
74
|
+
print(f"Config file location: {config.CONFIG_PATH}")
|
75
|
+
if config.CONFIG_PATH.exists():
|
76
|
+
print("\n=== Config file contents ===")
|
77
|
+
print(config.CONFIG_PATH.read_text(encoding="utf-8"))
|
78
|
+
else:
|
79
|
+
print("Config file does not exist. Use '--init' to create it.")
|
80
|
+
|
81
|
+
|
42
82
|
class Convert(_Command, base.Base):
|
43
83
|
"""AudioLibrarian tool for converting and tagging audio files.
|
44
84
|
|
@@ -56,9 +96,9 @@ class Convert(_Command, base.Base):
|
|
56
96
|
parser.add_argument("--disc", "-d", help="format: x/y: disc x of y for multi-disc release")
|
57
97
|
parser.add_argument("filename", nargs="+", help="directory name or audio file name")
|
58
98
|
|
59
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
99
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
60
100
|
"""Initialize a Convert command handler."""
|
61
|
-
super().__init__(args)
|
101
|
+
super().__init__(args, settings)
|
62
102
|
self._source_is_cd = False
|
63
103
|
self._audio_source = audiosource.FilesAudioSource([pathlib.Path(x) for x in args.filename])
|
64
104
|
self._get_tag_info()
|
@@ -88,9 +128,9 @@ class Genre(_Command):
|
|
88
128
|
parser_action.add_argument("--tag", action="store_true", help="update tags")
|
89
129
|
parser_action.add_argument("--update", action="store_true", help="update MusicBrainz")
|
90
130
|
|
91
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
131
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
92
132
|
"""Initialize a Genre command handler."""
|
93
|
-
genremanager.GenreManager(args)
|
133
|
+
genremanager.GenreManager(args=args, settings=settings.musicbrainz)
|
94
134
|
|
95
135
|
|
96
136
|
class Manifest(_Command, base.Base):
|
@@ -111,9 +151,9 @@ class Manifest(_Command, base.Base):
|
|
111
151
|
parser.add_argument("--disc", "-d", help="format: x/y: disc x of y for multi-disc release")
|
112
152
|
parser.add_argument("filename", nargs="+", help="directory name or audio file name")
|
113
153
|
|
114
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
154
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
115
155
|
"""Initialize a Manifest command handler."""
|
116
|
-
super().__init__(args)
|
156
|
+
super().__init__(args, settings)
|
117
157
|
self._source_is_cd = args.cd
|
118
158
|
self._audio_source = audiosource.FilesAudioSource([pathlib.Path(x) for x in args.filename])
|
119
159
|
source_filenames = self._audio_source.get_source_filenames()
|
@@ -139,9 +179,9 @@ class Reconvert(_Command, base.Base):
|
|
139
179
|
parser = argparse.ArgumentParser()
|
140
180
|
parser.add_argument("directories", nargs="+", help="source directories")
|
141
181
|
|
142
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
182
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
143
183
|
"""Initialize a Reconvert command handler."""
|
144
|
-
super().__init__(args)
|
184
|
+
super().__init__(args, settings)
|
145
185
|
self._source_is_cd = False
|
146
186
|
manifest_paths = self._find_manifests(args.directories)
|
147
187
|
count = len(manifest_paths)
|
@@ -172,9 +212,9 @@ class Rename(_Command, base.Base):
|
|
172
212
|
parser.add_argument("--dry-run", action="store_true", help="don't actually rename files")
|
173
213
|
parser.add_argument("directories", nargs="+", help="audio file directories")
|
174
214
|
|
175
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
215
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
176
216
|
"""Initialize a Rename command handler."""
|
177
|
-
super().__init__(args)
|
217
|
+
super().__init__(args, settings)
|
178
218
|
self._source_is_cd = False
|
179
219
|
print("Finding audio files...")
|
180
220
|
for audio_file in self._find_audio_files(args.directories):
|
@@ -233,11 +273,11 @@ class Rip(_Command, base.Base):
|
|
233
273
|
parser.add_argument("--mb-release-id", help="MusicBrainz release ID")
|
234
274
|
parser.add_argument("--disc", "-d", help="x/y: disc x of y; multi-disc release")
|
235
275
|
|
236
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
276
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
237
277
|
"""Initialize a Rip command handler."""
|
238
|
-
super().__init__(args)
|
278
|
+
super().__init__(args, settings)
|
239
279
|
self._source_is_cd = True
|
240
|
-
self._audio_source = audiosource.CDAudioSource()
|
280
|
+
self._audio_source = audiosource.CDAudioSource(settings)
|
241
281
|
self._get_tag_info()
|
242
282
|
self._convert()
|
243
283
|
self._write_manifest()
|
@@ -254,9 +294,10 @@ class Version(_Command):
|
|
254
294
|
command = "version"
|
255
295
|
help = "display the program version"
|
256
296
|
|
257
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
297
|
+
def __init__(self, args: argparse.Namespace, settings: config.Settings) -> None:
|
258
298
|
"""Initialize a Version command handler."""
|
259
|
-
_ = args
|
299
|
+
_, _ = args, settings
|
300
|
+
del args, settings # Unused.
|
260
301
|
print(f"audiolibrarian {__version__}")
|
261
302
|
|
262
303
|
|
@@ -280,4 +321,4 @@ def _validate_disc_arg(args: argparse.Namespace) -> bool:
|
|
280
321
|
return True
|
281
322
|
|
282
323
|
|
283
|
-
COMMANDS: set[Any] = {Convert, Genre, Manifest, Reconvert, Rename, Rip, Version}
|
324
|
+
COMMANDS: set[Any] = {Config, Convert, Genre, Manifest, Reconvert, Rename, Rip, Version}
|
@@ -7,8 +7,8 @@ sources of configuration:
|
|
7
7
|
- Prefix: "AUDIOLIBRARIAN__"
|
8
8
|
- Nested fields: Use "__" as delimiter (e.g., AUDIOLIBRARIAN__MUSICBRAINZ__USERNAME)
|
9
9
|
|
10
|
-
2.
|
11
|
-
- Location: $XDG_CONFIG_HOME/audiolibrarian/config.
|
10
|
+
2. TOML Configuration File:
|
11
|
+
- Location: $XDG_CONFIG_HOME/audiolibrarian/config.toml
|
12
12
|
- Supports nested structure for MusicBrainz settings
|
13
13
|
|
14
14
|
3. Default Values:
|
@@ -39,37 +39,51 @@ Sensitive fields (like passwords) are handled using pydantic.SecretStr for secur
|
|
39
39
|
#
|
40
40
|
import logging
|
41
41
|
import pathlib
|
42
|
-
from typing import Literal
|
42
|
+
from typing import Annotated, Final, Literal
|
43
43
|
|
44
44
|
import pydantic
|
45
45
|
import pydantic_settings
|
46
46
|
import xdg_base_dirs
|
47
47
|
|
48
|
+
CONFIG_PATH: Final[pathlib.Path] = (
|
49
|
+
xdg_base_dirs.xdg_config_home() / "audiolibrarian" / "config.toml"
|
50
|
+
)
|
51
|
+
|
48
52
|
logger = logging.getLogger(__name__)
|
49
53
|
|
54
|
+
ExpandedPath = Annotated[
|
55
|
+
pathlib.Path,
|
56
|
+
pydantic.AfterValidator(lambda v: v.expanduser()),
|
57
|
+
]
|
58
|
+
|
59
|
+
|
60
|
+
class EmptySettings(pydantic.BaseModel):
|
61
|
+
"""Empty settings."""
|
50
62
|
|
51
|
-
|
63
|
+
|
64
|
+
class MusicBrainzSettings(pydantic.BaseModel):
|
52
65
|
"""Configuration settings for MusicBrainz."""
|
53
66
|
|
54
67
|
password: pydantic.SecretStr = pydantic.SecretStr("")
|
55
68
|
username: str = ""
|
56
69
|
rate_limit: pydantic.PositiveFloat = 1.5 # Seconds between requests.
|
70
|
+
work_dir: ExpandedPath = xdg_base_dirs.xdg_cache_home() / "audiolibrarian"
|
57
71
|
|
58
72
|
|
59
|
-
class NormalizeFFmpegSettings(
|
73
|
+
class NormalizeFFmpegSettings(pydantic.BaseModel):
|
60
74
|
"""Configuration settings for ffmpeg normalization."""
|
61
75
|
|
62
76
|
target_level: float = -13
|
63
77
|
|
64
78
|
|
65
|
-
class NormalizeWavegainSettings(
|
79
|
+
class NormalizeWavegainSettings(pydantic.BaseModel):
|
66
80
|
"""Configuration settings for wavegain normalization."""
|
67
81
|
|
68
82
|
gain: int = 5 # dB
|
69
83
|
preset: Literal["album", "radio"] = "radio"
|
70
84
|
|
71
85
|
|
72
|
-
class NormalizeSettings(
|
86
|
+
class NormalizeSettings(pydantic.BaseModel):
|
73
87
|
"""Configuration settings for audio normalization."""
|
74
88
|
|
75
89
|
normalizer: Literal["auto", "wavegain", "ffmpeg", "none"] = "auto"
|
@@ -80,16 +94,16 @@ class NormalizeSettings(pydantic_settings.BaseSettings):
|
|
80
94
|
class Settings(pydantic_settings.BaseSettings):
|
81
95
|
"""Configuration settings for AudioLibrarian."""
|
82
96
|
|
83
|
-
discid_device: str
|
84
|
-
library_dir:
|
97
|
+
discid_device: str = "" # Use default device.
|
98
|
+
library_dir: ExpandedPath = pathlib.Path("library").resolve()
|
85
99
|
musicbrainz: MusicBrainzSettings = MusicBrainzSettings()
|
86
100
|
normalize: NormalizeSettings = NormalizeSettings()
|
87
|
-
work_dir:
|
101
|
+
work_dir: ExpandedPath = xdg_base_dirs.xdg_cache_home() / "audiolibrarian"
|
88
102
|
|
89
103
|
model_config = pydantic_settings.SettingsConfigDict(
|
90
104
|
env_nested_delimiter="__",
|
91
105
|
env_prefix="AUDIOLIBRARIAN__",
|
92
|
-
|
106
|
+
toml_file=str(CONFIG_PATH),
|
93
107
|
frozen=True, # Make settings immutable.
|
94
108
|
)
|
95
109
|
|
@@ -102,13 +116,37 @@ class Settings(pydantic_settings.BaseSettings):
|
|
102
116
|
dotenv_settings: pydantic_settings.PydanticBaseSettingsSource,
|
103
117
|
file_secret_settings: pydantic_settings.PydanticBaseSettingsSource,
|
104
118
|
) -> tuple[pydantic_settings.PydanticBaseSettingsSource, ...]:
|
119
|
+
"""Customize settings sources."""
|
105
120
|
del dotenv_settings, file_secret_settings # Unused.
|
106
121
|
return (
|
122
|
+
init_settings, # Used for tests.
|
107
123
|
env_settings,
|
108
|
-
pydantic_settings.
|
109
|
-
init_settings,
|
124
|
+
pydantic_settings.TomlConfigSettingsSource(settings_cls),
|
110
125
|
)
|
111
126
|
|
112
127
|
|
113
|
-
|
114
|
-
|
128
|
+
def init_config_file() -> None:
|
129
|
+
"""Initialize a new config file with default values.
|
130
|
+
|
131
|
+
The config file will be created at the location specified by CONFIG_PATH.
|
132
|
+
If the parent directory doesn't exist, it will be created.
|
133
|
+
|
134
|
+
Raises:
|
135
|
+
FileExistsError: If the config file already exists
|
136
|
+
OSError: If there's an error creating the file or directories
|
137
|
+
FileNotFoundError: If the template file cannot be found
|
138
|
+
"""
|
139
|
+
if CONFIG_PATH.exists():
|
140
|
+
msg = f"Config file already exists at {CONFIG_PATH}"
|
141
|
+
logger.warning(msg)
|
142
|
+
raise FileExistsError(msg)
|
143
|
+
|
144
|
+
# Create the config directory if it doesn't exist
|
145
|
+
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
|
146
|
+
|
147
|
+
# Get the directory where this file is located
|
148
|
+
template_dir = pathlib.Path(__file__).parent / "templates"
|
149
|
+
template_file = template_dir / CONFIG_PATH.name
|
150
|
+
|
151
|
+
# Read the template and write to the config file
|
152
|
+
CONFIG_PATH.write_text(template_file.read_text(encoding="utf-8"), encoding="utf-8")
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"""Entrypoints for audiolibrarian."""
|
2
|
+
#
|
3
|
+
# Copyright (c) 2000-2025 Stephen Jibson
|
4
|
+
#
|
5
|
+
# This file is part of audiolibrarian.
|
6
|
+
#
|
7
|
+
# Audiolibrarian is free software: you can redistribute it and/or modify it under the terms of the
|
8
|
+
# GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
9
|
+
# License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Audiolibrarian is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
12
|
+
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
13
|
+
# the GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License along with audiolibrarian.
|
16
|
+
# If not, see <https://www.gnu.org/licenses/>.
|
17
|
+
#
|
@@ -23,7 +23,7 @@ import subprocess
|
|
23
23
|
import sys
|
24
24
|
from typing import Final
|
25
25
|
|
26
|
-
from audiolibrarian import commands
|
26
|
+
from audiolibrarian import commands, config
|
27
27
|
|
28
28
|
log = logging.getLogger("audiolibrarian")
|
29
29
|
|
@@ -57,7 +57,7 @@ class CommandLineInterface:
|
|
57
57
|
if self._args.command == cmd.command:
|
58
58
|
if not cmd.validate_args(self._args):
|
59
59
|
sys.exit(2)
|
60
|
-
cmd(self._args)
|
60
|
+
cmd(self._args, config.Settings())
|
61
61
|
break
|
62
62
|
if self._args.log_level == logging.DEBUG:
|
63
63
|
print(pathlib.Path("/proc/self/status").read_text(encoding="utf-8"))
|
@@ -29,8 +29,7 @@ import mutagen.flac
|
|
29
29
|
import mutagen.id3
|
30
30
|
import mutagen.mp4
|
31
31
|
|
32
|
-
from audiolibrarian import musicbrainz, text
|
33
|
-
from audiolibrarian.settings import SETTINGS
|
32
|
+
from audiolibrarian import config, musicbrainz, text
|
34
33
|
|
35
34
|
log = logging.getLogger(__name__)
|
36
35
|
|
@@ -38,10 +37,11 @@ log = logging.getLogger(__name__)
|
|
38
37
|
class GenreManager:
|
39
38
|
"""Manage genres."""
|
40
39
|
|
41
|
-
def __init__(self, args: argparse.Namespace) -> None:
|
40
|
+
def __init__(self, args: argparse.Namespace, settings: config.MusicBrainzSettings) -> None:
|
42
41
|
"""Initialize a GenreManager instance."""
|
43
42
|
self._args = args
|
44
|
-
self.
|
43
|
+
self._settings = settings
|
44
|
+
self._mb = musicbrainz.MusicBrainzSession(settings=settings)
|
45
45
|
self._paths = self._get_all_paths()
|
46
46
|
self._paths_by_artist = self._get_paths_by_artist()
|
47
47
|
_u, _c = self._get_genres_by_artist()
|
@@ -149,7 +149,7 @@ class GenreManager:
|
|
149
149
|
user: dict[str, str] = {}
|
150
150
|
community: dict[str, dict[str, Any]] = {}
|
151
151
|
user_modified = False
|
152
|
-
cache_file =
|
152
|
+
cache_file = self._settings.work_dir / "user-genres.pickle"
|
153
153
|
if cache_file.exists():
|
154
154
|
with cache_file.open(mode="rb") as cache_file_obj:
|
155
155
|
user = pickle.load(cache_file_obj) # noqa: S301
|