audio-transcode-watcher 0.6.2__tar.gz → 0.7.1__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.
Files changed (63) hide show
  1. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/CHANGELOG.md +15 -0
  2. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/PKG-INFO +3 -2
  3. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/README.md +2 -1
  4. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/config.example.yaml +7 -1
  5. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/ROADMAP.md +3 -2
  6. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/configuration.md +28 -0
  7. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/getting-started.md +2 -2
  8. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/how-it-works.md +4 -0
  9. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/pyproject.toml +1 -1
  10. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/__init__.py +1 -1
  11. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/config.py +8 -0
  12. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/encoder.py +8 -6
  13. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/lyrics.py +1 -1
  14. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/main.py +13 -8
  15. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/manifest.py +34 -0
  16. audio_transcode_watcher-0.7.1/src/audio_transcode_watcher/replaygain.py +312 -0
  17. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/sync.py +104 -20
  18. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/utils.py +4 -0
  19. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/src/audio_transcode_watcher/watcher.py +4 -0
  20. audio_transcode_watcher-0.7.1/tests/test_replaygain.py +564 -0
  21. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/uv.lock +1 -1
  22. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/.gitignore +0 -0
  23. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/README.md +0 -0
  24. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/config.yaml +0 -0
  25. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/hooks/commit-msg +0 -0
  26. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/hooks/post-checkout +0 -0
  27. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/hooks/post-merge +0 -0
  28. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/hooks/pre-commit +0 -0
  29. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/hooks/pre-push +0 -0
  30. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/hooks/prepare-commit-msg +0 -0
  31. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.beads/metadata.json +0 -0
  32. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.claude/settings.json +0 -0
  33. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.coderabbit.yaml +0 -0
  34. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.github/FUNDING.yml +0 -0
  35. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.github/dependabot.yml +0 -0
  36. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.github/workflows/dockerhub-description.yml +0 -0
  37. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.github/workflows/release.yml +0 -0
  38. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.github/workflows/stale.yml +0 -0
  39. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.github/workflows/tests.yml +0 -0
  40. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/.gitignore +0 -0
  41. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/AGENTS.md +0 -0
  42. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/CLAUDE.md +0 -0
  43. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/Dockerfile +0 -0
  44. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/LICENSE +0 -0
  45. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/SECURITY.md +0 -0
  46. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/codecov.yml +0 -0
  47. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/development.md +0 -0
  48. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/images/banner.svg +0 -0
  49. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/images/icon.png +0 -0
  50. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/images/icon.svg +0 -0
  51. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/images/social-preview.png +0 -0
  52. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/docs/usage.md +0 -0
  53. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/__init__.py +0 -0
  54. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/conftest.py +0 -0
  55. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_config.py +0 -0
  56. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_encoder.py +0 -0
  57. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_lyrics.py +0 -0
  58. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_main.py +0 -0
  59. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_manifest.py +0 -0
  60. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_sync.py +0 -0
  61. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_utils.py +0 -0
  62. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tests/test_watcher.py +0 -0
  63. {audio_transcode_watcher-0.6.2 → audio_transcode_watcher-0.7.1}/tools/verify_sync.py +0 -0
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [0.7.1] - 2026-10-07
6
+
7
+ ### Fixed
8
+
9
+ - An output whose ReplayGain tags could not be written is now tried again on the next periodic sync. Before, one failed write (for example a root-owned ALAC file answering "Permission denied") marked its source as done, so the output stayed untagged until the source changed or the service restarted. Each failed attempt logs the same warning, and the source counts as done only once every output has its tags.
10
+ - Errors are no longer swallowed silently. File operations now catch only filesystem errors and log them as before. The broad catches that stay, such as the one around each file of a sync, log the full traceback, and lyric metadata reads and unreadable folders log at debug level. A failed removal of a leftover temp file is now logged too.
11
+
12
+ ## [0.7.0] - 2026-10-06
13
+
14
+ ### Added
15
+
16
+ - `replaygain: true` gives the whole library even volume. It is a top-level key and off by default. The watcher measures every source that has no `REPLAYGAIN_TRACK_GAIN` tag with FFmpeg's EBU R128 filter. It writes ReplayGain 2.0 track gain, -18 LUFS minus the integrated loudness, like `-6.32 dB`, and the true peak as a linear value, like `0.988553`, into the source file in its own tag format. That means Vorbis comments for FLAC, Ogg and Opus, `TXXX` frames for MP3, WAV and AIFF, freeform atoms for M4A, and APEv2 for APE, WavPack and TAK. Every output gets the same two tags. New encodes carry them, existing outputs get them in place without a re-encode, and lossy copies are copied again. The first sync covers the existing library, and every file added later gets the same treatment. The watcher writes no album gain, because the library may be one flat folder. It logs and skips a file it cannot measure. It also recognises its own tag writes and updates the manifest after each one, so tagging a source never re-encodes it or rebuilds a `tolerant` copy. See [ReplayGain](docs/configuration.md#replaygain).
17
+
5
18
  ## [0.6.2] - 2026-10-05
6
19
 
7
20
  ### Added
@@ -59,6 +72,8 @@ All notable changes to this project are documented here. The format follows [Kee
59
72
  - Lossy copies are written through a temp file and renamed, like encodes, so a half-written copy is never visible.
60
73
  - `force_reencode: true` purges the outputs once at startup. It used to purge them again on every periodic sync, which re-encoded the whole library every five minutes.
61
74
 
75
+ [0.7.1]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.7.1
76
+ [0.7.0]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.7.0
62
77
  [0.6.2]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.6.2
63
78
  [0.6.1]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.6.1
64
79
  [0.6.0]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.6.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: audio-transcode-watcher
3
- Version: 0.6.2
3
+ Version: 0.7.1
4
4
  Summary: Watch a source folder and automatically transcode audio files to multiple formats
5
5
  Project-URL: Homepage, https://github.com/GeiserX/audio-transcode-watcher
6
6
  Project-URL: Repository, https://github.com/GeiserX/audio-transcode-watcher
@@ -54,6 +54,7 @@ Keep one library in several formats: lossless for the archive, lossy for phones
54
54
  - Copies lossy sources (MP3, M4A, Ogg, Opus, WMA) unchanged instead of inflating them into a lossless output.
55
55
  - Fails loudly on a source that does not decode cleanly, and writes no output for it.
56
56
  - Keeps ReplayGain, MusicBrainz ids, ISRC, label and sort tags in ALAC and AAC copies.
57
+ - Optionally measures every file and writes ReplayGain 2.0 track gain into the source and every output, so the whole library plays at one volume.
57
58
  - Fetches synced `.lrc` lyrics, and writes nothing when no real lyrics are found.
58
59
  - Embeds cover art if you want it.
59
60
  - Writes atomically and removes orphaned outputs, but never deletes anything when a folder looks empty.
@@ -66,7 +67,7 @@ Keep one library in several formats: lossless for the archive, lossy for phones
66
67
  curl -fsSL -o config.yaml https://raw.githubusercontent.com/GeiserX/audio-transcode-watcher/main/config.example.yaml
67
68
  docker run -d --name audio_transcoder -e CONFIG_FILE=/app/config.yaml \
68
69
  -v ./config.yaml:/app/config.yaml:ro -v /path/to/flac:/music/flac:ro -v /path/to/mp3:/music/mp3 \
69
- drumsergio/audio-transcoder:0.6.2
70
+ drumsergio/audio-transcoder:0.7.1
70
71
  ```
71
72
 
72
73
  Edit `config.yaml` first so its outputs match the folders you mount; the example writes ALAC, MP3 and AAC. [Getting started](https://github.com/GeiserX/audio-transcode-watcher/blob/main/docs/getting-started.md) has Docker Compose and the full `docker run`.
@@ -23,6 +23,7 @@ Keep one library in several formats: lossless for the archive, lossy for phones
23
23
  - Copies lossy sources (MP3, M4A, Ogg, Opus, WMA) unchanged instead of inflating them into a lossless output.
24
24
  - Fails loudly on a source that does not decode cleanly, and writes no output for it.
25
25
  - Keeps ReplayGain, MusicBrainz ids, ISRC, label and sort tags in ALAC and AAC copies.
26
+ - Optionally measures every file and writes ReplayGain 2.0 track gain into the source and every output, so the whole library plays at one volume.
26
27
  - Fetches synced `.lrc` lyrics, and writes nothing when no real lyrics are found.
27
28
  - Embeds cover art if you want it.
28
29
  - Writes atomically and removes orphaned outputs, but never deletes anything when a folder looks empty.
@@ -35,7 +36,7 @@ Keep one library in several formats: lossless for the archive, lossy for phones
35
36
  curl -fsSL -o config.yaml https://raw.githubusercontent.com/GeiserX/audio-transcode-watcher/main/config.example.yaml
36
37
  docker run -d --name audio_transcoder -e CONFIG_FILE=/app/config.yaml \
37
38
  -v ./config.yaml:/app/config.yaml:ro -v /path/to/flac:/music/flac:ro -v /path/to/mp3:/music/mp3 \
38
- drumsergio/audio-transcoder:0.6.2
39
+ drumsergio/audio-transcoder:0.7.1
39
40
  ```
40
41
 
41
42
  Edit `config.yaml` first so its outputs match the folders you mount; the example writes ALAC, MP3 and AAC. [Getting started](https://github.com/GeiserX/audio-transcode-watcher/blob/main/docs/getting-started.md) has Docker Compose and the full `docker run`.
@@ -1,4 +1,4 @@
1
- # Audio Transcode Watcher Configuration (0.6.2)
1
+ # Audio Transcode Watcher Configuration (0.7.1)
2
2
  # ======================================
3
3
  #
4
4
  # This configuration file defines the source folder and output destinations
@@ -41,6 +41,12 @@ outputs:
41
41
  channels: 2
42
42
  max_sample_rate: 48000
43
43
 
44
+ # Even volume across the library (default: false). Every source without a
45
+ # REPLAYGAIN_TRACK_GAIN tag is measured (EBU R128) and gets ReplayGain 2.0
46
+ # track gain and peak tags, written into the source file itself. Every output
47
+ # gets the same tags, without being re-encoded. No album gain is written.
48
+ replaygain: false
49
+
44
50
  # Optional settings
45
51
  settings:
46
52
  # Set to true to delete all outputs and re-encode everything on startup
@@ -1,6 +1,6 @@
1
1
  # Roadmap
2
2
 
3
- Current version: **0.6.2**
3
+ Current version: **0.7.1**
4
4
 
5
5
  ## Completed
6
6
 
@@ -14,8 +14,9 @@ Current version: **0.6.2**
14
14
  - **Lossy sources copied, not inflated**, corrupt sources fail loudly, ReplayGain and MusicBrainz tags kept in M4A outputs, configurable periodic sync (v0.6.0)
15
15
  - **Portable AAC**: stereo downmix and a 48 kHz cap for AAC outputs, per-output `channels` and `max_sample_rate` (v0.6.1)
16
16
  - **Damaged sources**: `corrupt_source: encode_anyway` makes a concealed copy instead of none (v0.6.2)
17
+ - **Even volume**: `replaygain: true` writes ReplayGain 2.0 track tags into every source and output (v0.7.0)
17
18
 
18
- ## v0.7.0 -- Quality of Life
19
+ ## v0.7.x -- Quality of Life
19
20
 
20
21
  - [ ] **Progress reporting during initial sync**
21
22
  - Show file count progress (e.g. 42/500)
@@ -44,6 +44,9 @@ outputs:
44
44
  bitrate: 128k
45
45
  path: /music/opus
46
46
 
47
+ # Even volume: write ReplayGain 2.0 track tags (default: false)
48
+ replaygain: false
49
+
47
50
  # Optional settings
48
51
  settings:
49
52
  # Delete all outputs and re-encode on startup
@@ -84,6 +87,31 @@ Set it under `settings` for every output, or on one output to override, for exam
84
87
 
85
88
  Either way the source is remembered as failed, so the strict attempt is not repeated on every scan. Replacing the file with a clean copy (a new size or modification time) clears that, and the next scan rebuilds the tolerant copy with the strict encode.
86
89
 
90
+ ### ReplayGain
91
+
92
+ With `replaygain: true` at the top level of the config, every track plays at the same loudness in any player that reads ReplayGain tags, such as Navidrome and foobar2000:
93
+
94
+ ```yaml
95
+ replaygain: true
96
+ ```
97
+
98
+ For each source that has no `REPLAYGAIN_TRACK_GAIN` tag yet, the watcher measures its loudness with FFmpeg's EBU R128 filter and writes two tags into the source file:
99
+
100
+ - `REPLAYGAIN_TRACK_GAIN`: -18 LUFS minus the measured integrated loudness, for example `-6.32 dB`.
101
+ - `REPLAYGAIN_TRACK_PEAK`: the true peak as a linear value, for example `0.988553`.
102
+
103
+ They are written in the file's own tag format: Vorbis comments in FLAC, Ogg and Opus, `TXXX` frames in MP3, WAV and AIFF, freeform atoms in M4A, and APEv2 in APE, WavPack and TAK. An ID3v2.3 file stays at 2.3. The M4A atoms use the names Picard writes, such as `----:com.apple.iTunes:replaygain_track_gain`. Raw `.aac` and `.wma` sources are left alone. A source that already has a track gain from any tool is never measured again, and a silent file gets no tag.
104
+
105
+ Every output gets the same two tags. New encodes carry them from the source. The watcher writes them into outputs that already exist without re-encoding them, and copies lossy sources again so each copy stays identical to its source.
106
+
107
+ This applies to the whole library on the first sync after you turn it on, and then to every file that arrives. The first pass decodes each untagged source once, through the same `parallel_workers` as encoding, so a large library takes a while. The watcher logs and skips a file it cannot measure, and tries it again after the next restart.
108
+
109
+ The watcher writes no album gain. Album gain needs to know which files form an album, and a folder does not say that reliably. Many libraries are one flat folder.
110
+
111
+ Writing the tags changes the source file's size and modification time. The watcher recognises its own writes, so a tagged source is not treated as a new version and nothing is re-encoded. Other tools that watch the source folder, like a media server's library scan or a sync job, see the change once.
112
+
113
+ `replaygain` is also accepted under `settings`.
114
+
87
115
  `whisper_fallback` and `whisper_model` were removed in 0.6.0 along with the Whisper lyrics fallback. A config that still sets them loads, and the first load logs one warning that they are ignored.
88
116
 
89
117
  ## Source formats
@@ -29,7 +29,7 @@ outputs:
29
29
  ```yaml
30
30
  services:
31
31
  audio-transcoder:
32
- image: drumsergio/audio-transcoder:0.6.2
32
+ image: drumsergio/audio-transcoder:0.7.1
33
33
  container_name: audio_transcoder
34
34
  environment:
35
35
  - TZ=Europe/Madrid
@@ -60,6 +60,6 @@ docker run -d \
60
60
  -v /path/to/flac:/music/flac:ro \
61
61
  -v /path/to/mp3:/music/mp3 \
62
62
  --restart unless-stopped \
63
- drumsergio/audio-transcoder:0.6.2
63
+ drumsergio/audio-transcoder:0.7.1
64
64
  ```
65
65
 
@@ -19,6 +19,10 @@ Each output folder holds `.atw-manifest.json`, a map from each output file to th
19
19
 
20
20
  FFmpeg runs with `-xerror` and `-err_detect crccheck+explode`, so a frame whose checksum does not match stops the encode. If a source does not decode cleanly, the encode fails even when FFmpeg exits 0 but printed a decode error. The error is logged with the file name and no output is written, unless `corrupt_source: encode_anyway` is set; then the file is encoded once more with FFmpeg's error concealment and marked `tolerant` in the manifest (see [Damaged sources](configuration.md#damaged-sources)). The strict attempt is not repeated until the file's modification time changes, or the service restarts.
21
21
 
22
+ ## ReplayGain
23
+
24
+ With `replaygain: true`, each source is checked before its outputs are written. The watcher measures a source with no `REPLAYGAIN_TRACK_GAIN` tag with FFmpeg's `ebur128` filter and tags it in place before encoding, so new outputs carry the tags. It writes the tags into existing outputs that lack them and copies lossy copies again. Each source is checked once per run of the service, and again only when its size or modification time changes. After a tag write, the manifest rows that described the source or output as it was are updated to match, so a `tolerant` copy is not rebuilt, and the watcher ignores the file events its own write causes. See [ReplayGain](configuration.md#replaygain).
25
+
22
26
  ## Recursive Directory Support
23
27
 
24
28
  Source folder hierarchy is automatically mirrored in all outputs. Both flat and nested structures work out of the box -- no configuration needed.
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
  [project]
6
6
  name = "audio-transcode-watcher"
7
7
 
8
- version = "0.6.2"
8
+ version = "0.7.1"
9
9
 
10
10
  description = "Watch a source folder and automatically transcode audio files to multiple formats"
11
11
  readme = "README.md"
@@ -1,3 +1,3 @@
1
1
  """Audio Transcode Watcher - Automatic audio file transcoding."""
2
2
 
3
- __version__ = "0.6.2"
3
+ __version__ = "0.7.1"
@@ -143,12 +143,17 @@ class Config:
143
143
  fetch_lyrics: bool = True # Auto-fetch .lrc lyrics via syncedlyrics
144
144
  sync_interval_seconds: int = 300 # Seconds between periodic full syncs
145
145
  corrupt_source: str = "skip" # Default for outputs that don't set it
146
+ replaygain: bool = False # Write ReplayGain 2.0 track tags (top-level key)
146
147
 
147
148
  def __post_init__(self) -> None:
148
149
  """Validate configuration after initialization."""
149
150
  if not self.source_path:
150
151
  raise ValueError("source_path is required")
151
152
 
153
+ if not isinstance(self.replaygain, bool):
154
+ # ValueError, like every other config error, so main reports it.
155
+ raise ValueError("replaygain must be true or false") # noqa: TRY004
156
+
152
157
  _check_corrupt_source(self.corrupt_source, "settings.corrupt_source")
153
158
 
154
159
  interval = self.sync_interval_seconds
@@ -206,6 +211,9 @@ class Config:
206
211
  fetch_lyrics=settings.get("fetch_lyrics", True),
207
212
  sync_interval_seconds=settings.get("sync_interval_seconds", 300),
208
213
  corrupt_source=settings.get("corrupt_source", "skip"),
214
+ # Documented at the top level; also read under settings, where
215
+ # every other option lives, so either place works.
216
+ replaygain=data.get("replaygain", settings.get("replaygain", False)),
209
217
  )
210
218
 
211
219
  @classmethod
@@ -347,8 +347,8 @@ def atomic_ffmpeg_encode(
347
347
  try:
348
348
  if os.path.exists(tmp_dest):
349
349
  os.remove(tmp_dest)
350
- except Exception:
351
- pass
350
+ except OSError as e:
351
+ logger.warning("Could not remove stale temp file %s: %s", tmp_dest, e)
352
352
 
353
353
  # Replace destination with temp path
354
354
  cmd = list(cmd)
@@ -378,12 +378,14 @@ def atomic_ffmpeg_encode(
378
378
  try:
379
379
  finalize(tmp_dest)
380
380
  except Exception as e:
381
- logger.warning("Post-encode step failed for %s: %s", final_dest, e)
381
+ logger.warning(
382
+ "Post-encode step failed for %s: %s", final_dest, e, exc_info=True
383
+ )
382
384
 
383
385
  try:
384
386
  os.replace(tmp_dest, final_dest)
385
387
  return 0
386
- except Exception as e:
388
+ except OSError as e:
387
389
  logger.error("Atomic replace failed for %s: %s", final_dest, e)
388
390
  _cleanup_temp(tmp_dest)
389
391
  return 1
@@ -464,5 +466,5 @@ def _cleanup_temp(path: str) -> None:
464
466
  try:
465
467
  if os.path.exists(path):
466
468
  os.remove(path)
467
- except Exception:
468
- pass
469
+ except OSError as e:
470
+ logger.warning("Could not remove temp file %s: %s", path, e)
@@ -75,7 +75,7 @@ def extract_metadata(filepath: str) -> tuple[str, str] | None:
75
75
  if artist and title:
76
76
  return artist, title
77
77
  except Exception:
78
- logger.debug("Could not read metadata from %s", filepath)
78
+ logger.debug("Could not read metadata from %s", filepath, exc_info=True)
79
79
 
80
80
  # Fallback: parse filename "Artist - Title.ext"
81
81
  stem = Path(filepath).stem
@@ -16,20 +16,22 @@ from .watcher import start_watcher
16
16
 
17
17
  def setup_logging() -> None:
18
18
  """Configure logging for the application."""
19
- # Ensure Unicode output works
19
+ logging.basicConfig(
20
+ level=logging.INFO,
21
+ format="%(asctime)s %(levelname)s: %(message)s",
22
+ datefmt="%H:%M:%S",
23
+ )
24
+
25
+ # Ensure Unicode output works (reconfigure changes the stream in place,
26
+ # so the handler above writes UTF-8 too)
20
27
  try:
21
28
  if hasattr(sys.stdout, "reconfigure"):
22
29
  sys.stdout.reconfigure(encoding="utf-8")
23
30
  if hasattr(sys.stderr, "reconfigure"):
24
31
  sys.stderr.reconfigure(encoding="utf-8")
25
32
  except Exception:
26
- pass
27
-
28
- logging.basicConfig(
29
- level=logging.INFO,
30
- format="%(asctime)s %(levelname)s: %(message)s",
31
- datefmt="%H:%M:%S",
32
- )
33
+ logger = logging.getLogger(__name__)
34
+ logger.warning("Could not switch output to UTF-8", exc_info=True)
33
35
 
34
36
 
35
37
  def main() -> int:
@@ -65,6 +67,9 @@ def main() -> int:
65
67
  output.path,
66
68
  )
67
69
 
70
+ if config.replaygain:
71
+ logger.info("ReplayGain: sources and outputs get track gain tags")
72
+
68
73
  # Perform initial sync
69
74
  initial_sync(config)
70
75
 
@@ -112,6 +112,40 @@ def output_matches(row: dict, out_path: str) -> bool:
112
112
  )
113
113
 
114
114
 
115
+ def restat(
116
+ root: str,
117
+ out_path: str,
118
+ before: os.stat_result,
119
+ source_path: str | None = None,
120
+ ) -> None:
121
+ """
122
+ Keep *out_path*'s row trusted after a file was edited in place.
123
+
124
+ A tag write changes a file's size and mtime. With *source_path*, the
125
+ edited file is the source: the row's source size and mtime are updated
126
+ if they matched *before*. Without it, the edited file is *out_path*
127
+ and its output size and mtime are updated the same way. A row that no
128
+ longer described the file before the edit is left alone.
129
+ """
130
+ edited = source_path or out_path
131
+ try:
132
+ st = os.stat(edited)
133
+ except OSError:
134
+ return
135
+ fields = ("size", "mtime") if source_path else ("output_size", "output_mtime")
136
+ with _lock:
137
+ row = _load(root).get(_key(root, out_path))
138
+ if not row:
139
+ return
140
+ if (row.get(fields[0]), row.get(fields[1])) != (
141
+ before.st_size,
142
+ before.st_mtime,
143
+ ):
144
+ return
145
+ row[fields[0]], row[fields[1]] = st.st_size, st.st_mtime
146
+ _dirty.add(root)
147
+
148
+
115
149
  def prune(root: str) -> int:
116
150
  """Drop rows whose output file is gone. Returns how many were dropped."""
117
151
  with _lock: