audio-transcode-watcher 0.6.1__tar.gz → 0.7.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.
Files changed (63) hide show
  1. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/config.yaml +2 -2
  2. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/AGENTS.md +1 -1
  3. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/CHANGELOG.md +14 -0
  4. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/CLAUDE.md +1 -1
  5. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/PKG-INFO +3 -2
  6. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/README.md +2 -1
  7. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/config.example.yaml +14 -1
  8. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/ROADMAP.md +4 -2
  9. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/configuration.md +50 -0
  10. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/getting-started.md +2 -2
  11. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/how-it-works.md +5 -1
  12. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/pyproject.toml +1 -1
  13. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/__init__.py +1 -1
  14. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/config.py +31 -0
  15. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/encoder.py +33 -6
  16. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/main.py +3 -0
  17. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/manifest.py +34 -0
  18. audio_transcode_watcher-0.7.0/src/audio_transcode_watcher/replaygain.py +312 -0
  19. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/sync.py +128 -13
  20. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/watcher.py +4 -0
  21. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_config.py +36 -0
  22. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_encoder.py +41 -0
  23. audio_transcode_watcher-0.7.0/tests/test_replaygain.py +521 -0
  24. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_sync.py +265 -0
  25. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/uv.lock +1 -1
  26. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/.gitignore +0 -0
  27. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/README.md +0 -0
  28. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/hooks/commit-msg +0 -0
  29. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/hooks/post-checkout +0 -0
  30. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/hooks/post-merge +0 -0
  31. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/hooks/pre-commit +0 -0
  32. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/hooks/pre-push +0 -0
  33. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/hooks/prepare-commit-msg +0 -0
  34. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.beads/metadata.json +0 -0
  35. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.claude/settings.json +0 -0
  36. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.coderabbit.yaml +0 -0
  37. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.github/FUNDING.yml +0 -0
  38. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.github/dependabot.yml +0 -0
  39. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.github/workflows/dockerhub-description.yml +0 -0
  40. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.github/workflows/release.yml +0 -0
  41. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.github/workflows/stale.yml +0 -0
  42. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.github/workflows/tests.yml +0 -0
  43. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/.gitignore +0 -0
  44. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/Dockerfile +0 -0
  45. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/LICENSE +0 -0
  46. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/SECURITY.md +0 -0
  47. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/codecov.yml +0 -0
  48. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/development.md +0 -0
  49. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/images/banner.svg +0 -0
  50. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/images/icon.png +0 -0
  51. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/images/icon.svg +0 -0
  52. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/images/social-preview.png +0 -0
  53. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/docs/usage.md +0 -0
  54. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/lyrics.py +0 -0
  55. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/src/audio_transcode_watcher/utils.py +0 -0
  56. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/__init__.py +0 -0
  57. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/conftest.py +0 -0
  58. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_lyrics.py +0 -0
  59. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_main.py +0 -0
  60. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_manifest.py +0 -0
  61. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_utils.py +0 -0
  62. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tests/test_watcher.py +0 -0
  63. {audio_transcode_watcher-0.6.1 → audio_transcode_watcher-0.7.0}/tools/verify_sync.py +0 -0
@@ -65,7 +65,7 @@
65
65
  # - linear.api_key → use LINEAR_API_KEY env var instead
66
66
  # - github.token → use GITHUB_TOKEN env var instead
67
67
 
68
- # Public repo: the tracker syncs only to this private Gitea repo, never to GitHub.
69
- sync.remote: "git+ssh://git@gitea.geiser.cloud:2222/giteaer/audio-transcode-watcher-beads.git"
68
+ # Public repo: the tracker syncs only to this private remote, never to GitHub.
69
+ sync.remote: "git+ssh://git@beads-tracker/giteaer/audio-transcode-watcher-beads.git"
70
70
  # Every bd write is a Dolt commit, so a push always carries it.
71
71
  dolt.auto-commit: "on"
@@ -104,4 +104,4 @@ This protocol applies when ending a Beads implementation workflow. It is subordi
104
104
 
105
105
  ## Where the tracker syncs
106
106
 
107
- This repo is public, so its tracker syncs only to the private Dolt remote named by `sync.remote` in `.beads/config.yaml` (`giteaer/audio-transcode-watcher-beads` on Gitea). The block above says sync uses "your git remote". Here that never means this GitHub repo. Don't add it as a Dolt remote and don't push `refs/dolt/*` to it.
107
+ This repo is public, so its tracker syncs only to the private remote named by `sync.remote` in `.beads/config.yaml`. The block above says sync uses "your git remote". Here that never means this GitHub repo. Don't add it as a Dolt remote and don't push `refs/dolt/*` to it.
@@ -2,6 +2,18 @@
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.0] - 2026-10-06
6
+
7
+ ### Added
8
+
9
+ - `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).
10
+
11
+ ## [0.6.2] - 2026-10-05
12
+
13
+ ### Added
14
+
15
+ - `corrupt_source: skip | encode_anyway`, under `settings` or on one output (default `skip`, the 0.6.1 behaviour). Some damaged FLACs have no clean copy to replace them, and refusing them leaves the phone with no copy of the song at all. With `encode_anyway`, a source that fails the strict decode still gets the same ERROR line, then one more encode without `-xerror` and `-err_detect`, so FFmpeg conceals the damaged frames. That copy is logged with one WARNING saying it was made from a damaged source, and its manifest row has kind `tolerant`. The source is still remembered as failed, so the strict attempt is not repeated on every scan, and a source that fails even the tolerant encode stays refused. When the damaged file is later replaced by a clean one (a different size or modification time), the next scan rebuilds the tolerant copy with the strict encode.
16
+
5
17
  ## [0.6.1] - 2026-10-04
6
18
 
7
19
  ### Added
@@ -53,5 +65,7 @@ All notable changes to this project are documented here. The format follows [Kee
53
65
  - Lossy copies are written through a temp file and renamed, like encodes, so a half-written copy is never visible.
54
66
  - `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.
55
67
 
68
+ [0.7.0]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.7.0
69
+ [0.6.2]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.6.2
56
70
  [0.6.1]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.6.1
57
71
  [0.6.0]: https://github.com/GeiserX/audio-transcode-watcher/releases/tag/v0.6.0
@@ -100,4 +100,4 @@ This protocol applies when ending a Beads implementation workflow. It is subordi
100
100
 
101
101
  ## Where the tracker syncs
102
102
 
103
- This repo is public, so its tracker syncs only to the private Dolt remote named by `sync.remote` in `.beads/config.yaml` (`giteaer/audio-transcode-watcher-beads` on Gitea). The block above says sync uses "your git remote". Here that never means this GitHub repo. Don't add it as a Dolt remote and don't push `refs/dolt/*` to it.
103
+ This repo is public, so its tracker syncs only to the private remote named by `sync.remote` in `.beads/config.yaml`. The block above says sync uses "your git remote". Here that never means this GitHub repo. Don't add it as a Dolt remote and don't push `refs/dolt/*` to it.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: audio-transcode-watcher
3
- Version: 0.6.1
3
+ Version: 0.7.0
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.1
70
+ drumsergio/audio-transcoder:0.7.0
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.1
39
+ drumsergio/audio-transcoder:0.7.0
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.1)
1
+ # Audio Transcode Watcher Configuration (0.7.0)
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
@@ -62,6 +68,13 @@ settings:
62
68
  # Seconds between periodic full syncs (default: 300)
63
69
  sync_interval_seconds: 300
64
70
 
71
+ # A source that does not decode cleanly (a damaged FLAC):
72
+ # skip write nothing for it (default)
73
+ # encode_anyway log the error, then encode it with FFmpeg's error
74
+ # concealment, so a one-frame glitch is better than no copy
75
+ # An output can set its own corrupt_source to override this.
76
+ corrupt_source: skip
77
+
65
78
  # whisper_fallback and whisper_model were removed in 0.6.0 and are ignored
66
79
 
67
80
 
@@ -1,6 +1,6 @@
1
1
  # Roadmap
2
2
 
3
- Current version: **0.6.1**
3
+ Current version: **0.7.0**
4
4
 
5
5
  ## Completed
6
6
 
@@ -13,8 +13,10 @@ Current version: **0.6.1**
13
13
  - **Recursive directory support** -- mirror source folder hierarchy in outputs (v0.5.0)
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
+ - **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)
16
18
 
17
- ## v0.7.0 -- Quality of Life
19
+ ## v0.7.x -- Quality of Life
18
20
 
19
21
  - [ ] **Progress reporting during initial sync**
20
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
@@ -60,8 +63,55 @@ settings:
60
63
 
61
64
  # Seconds between periodic full syncs (default: 300)
62
65
  sync_interval_seconds: 300
66
+
67
+ # What to do with a source that does not decode cleanly: skip | encode_anyway
68
+ # (default: skip). An output can set its own corrupt_source.
69
+ corrupt_source: skip
70
+ ```
71
+
72
+ ### Damaged sources
73
+
74
+ A source that fails the strict decode (see [Corrupt sources](how-it-works.md#corrupt-sources)) is handled by `corrupt_source`:
75
+
76
+ - `skip` (the default) writes nothing for it.
77
+ - `encode_anyway` logs the same ERROR, then encodes it once more without `-xerror` and `-err_detect`, letting FFmpeg conceal the damaged frames. The copy exists, one WARNING line says it was made from a damaged source, and its manifest row has kind `tolerant`. A source that fails even that run stays refused.
78
+
79
+ Set it under `settings` for every output, or on one output to override, for example only on the AAC output that a phone plays from:
80
+
81
+ ```yaml
82
+ - name: aac-256
83
+ codec: aac
84
+ path: /music/aac
85
+ corrupt_source: encode_anyway
86
+ ```
87
+
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.
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
63
96
  ```
64
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
+
65
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.
66
116
 
67
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.1
32
+ image: drumsergio/audio-transcoder:0.7.0
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.1
63
+ drumsergio/audio-transcoder:0.7.0
64
64
  ```
65
65
 
@@ -17,7 +17,11 @@ Each output folder holds `.atw-manifest.json`, a map from each output file to th
17
17
 
18
18
  ## Corrupt sources
19
19
 
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. The file is not tried again until its modification time changes, or the service restarts.
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
+
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).
21
25
 
22
26
  ## Recursive Directory Support
23
27
 
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
  [project]
6
6
  name = "audio-transcode-watcher"
7
7
 
8
- version = "0.6.1"
8
+ version = "0.7.0"
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.1"
3
+ __version__ = "0.7.0"
@@ -45,10 +45,19 @@ DEFAULT_BITRATES = {
45
45
  # Portable-playback limits applied when an output does not set them.
46
46
  # AAC goes to phones, AirPods and CarPlay: stereo, at most 48 kHz.
47
47
  # Any codec can opt in by setting channels / max_sample_rate; 0 = no limit.
48
+ # What to do with a source that does not decode cleanly: "skip" writes
49
+ # nothing; "encode_anyway" retries with ffmpeg's error concealment.
50
+ CORRUPT_SOURCE_MODES = ("skip", "encode_anyway")
51
+
48
52
  DEFAULT_CHANNELS = {"aac": 2}
49
53
  DEFAULT_MAX_SAMPLE_RATE = {"aac": 48000}
50
54
 
51
55
 
56
+ def _check_corrupt_source(value: Any, label: str) -> None:
57
+ if value not in CORRUPT_SOURCE_MODES:
58
+ raise ValueError(f"{label} must be one of {', '.join(CORRUPT_SOURCE_MODES)}")
59
+
60
+
52
61
  @dataclass
53
62
  class OutputConfig:
54
63
  """Configuration for a single output destination."""
@@ -60,6 +69,7 @@ class OutputConfig:
60
69
  include_artwork: bool = True
61
70
  channels: int | None = None # Downmix above this many channels; 0 = keep
62
71
  max_sample_rate: int | None = None # Resample above this rate (Hz); 0 = keep
72
+ corrupt_source: str | None = None # "skip" | "encode_anyway"; None = global
63
73
 
64
74
  def __post_init__(self) -> None:
65
75
  """Validate and set defaults after initialization."""
@@ -83,6 +93,10 @@ class OutputConfig:
83
93
  self.channels = DEFAULT_CHANNELS.get(self.codec, 0)
84
94
  if self.max_sample_rate is None:
85
95
  self.max_sample_rate = DEFAULT_MAX_SAMPLE_RATE.get(self.codec, 0)
96
+ if self.corrupt_source is not None:
97
+ _check_corrupt_source(
98
+ self.corrupt_source, f"Output '{self.name}': corrupt_source"
99
+ )
86
100
  for key in ("channels", "max_sample_rate"):
87
101
  value = getattr(self, key)
88
102
  if isinstance(value, bool) or not isinstance(value, int) or value < 0:
@@ -111,6 +125,7 @@ class OutputConfig:
111
125
  include_artwork=data.get("include_artwork", True),
112
126
  channels=data.get("channels"),
113
127
  max_sample_rate=data.get("max_sample_rate"),
128
+ corrupt_source=data.get("corrupt_source"),
114
129
  )
115
130
 
116
131
 
@@ -127,12 +142,20 @@ class Config:
127
142
  min_stable_seconds: float = 1.0
128
143
  fetch_lyrics: bool = True # Auto-fetch .lrc lyrics via syncedlyrics
129
144
  sync_interval_seconds: int = 300 # Seconds between periodic full syncs
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)
130
147
 
131
148
  def __post_init__(self) -> None:
132
149
  """Validate configuration after initialization."""
133
150
  if not self.source_path:
134
151
  raise ValueError("source_path is required")
135
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
+
157
+ _check_corrupt_source(self.corrupt_source, "settings.corrupt_source")
158
+
136
159
  interval = self.sync_interval_seconds
137
160
  if (
138
161
  isinstance(interval, bool)
@@ -159,6 +182,10 @@ class Config:
159
182
  """Get list of all output directory paths."""
160
183
  return [o.path for o in self.outputs]
161
184
 
185
+ def corrupt_source_for(self, output: OutputConfig) -> str:
186
+ """The corrupt_source mode for *output*: its own, else the global one."""
187
+ return output.corrupt_source or self.corrupt_source
188
+
162
189
  def get_output_by_name(self, name: str) -> OutputConfig | None:
163
190
  """Get an output configuration by name."""
164
191
  for output in self.outputs:
@@ -183,6 +210,10 @@ class Config:
183
210
  min_stable_seconds=settings.get("min_stable_seconds", 1.0),
184
211
  fetch_lyrics=settings.get("fetch_lyrics", True),
185
212
  sync_interval_seconds=settings.get("sync_interval_seconds", 300),
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)),
186
217
  )
187
218
 
188
219
  @classmethod
@@ -275,8 +275,31 @@ def _is_artwork_error(stderr: str) -> bool:
275
275
  return any(h in low for h in _ARTWORK_ERROR_HINTS)
276
276
 
277
277
 
278
- def _run_ffmpeg(cmd: list[str]) -> tuple[int, str]:
279
- """Run ffmpeg; a decode error on stderr counts as a failure even with rc 0."""
278
+ def tolerant_command(cmd: list[str]) -> list[str]:
279
+ """*cmd* without -xerror and -err_detect, so ffmpeg conceals decode errors."""
280
+ out: list[str] = []
281
+ skip = False
282
+ for i, arg in enumerate(cmd):
283
+ if skip:
284
+ skip = False
285
+ continue
286
+ if arg == "-xerror":
287
+ continue
288
+ if arg == "-err_detect" and i + 1 < len(cmd):
289
+ skip = True
290
+ continue
291
+ out.append(arg)
292
+ return out
293
+
294
+
295
+ def _run_ffmpeg(cmd: list[str], strict: bool = True) -> tuple[int, str]:
296
+ """
297
+ Run ffmpeg and return (rc, stderr).
298
+
299
+ Strict: a decode error on stderr is a failure even with rc 0, and any
300
+ failure that reports a decode error returns DECODE_ERROR_RC. Not strict:
301
+ only the exit code counts (concealed errors still print to stderr).
302
+ """
280
303
  try:
281
304
  proc = subprocess.run(
282
305
  cmd, capture_output=True, timeout=FFMPEG_TIMEOUT, check=False
@@ -285,7 +308,7 @@ def _run_ffmpeg(cmd: list[str]) -> tuple[int, str]:
285
308
  return TIMEOUT_RC, f"ffmpeg timed out after {FFMPEG_TIMEOUT} s"
286
309
  stderr = proc.stderr.decode("utf-8", errors="ignore") if proc.stderr else ""
287
310
  rc = proc.returncode
288
- if rc == 0 and _decode_error(stderr):
311
+ if strict and _decode_error(stderr):
289
312
  rc = DECODE_ERROR_RC
290
313
  return rc, stderr
291
314
 
@@ -295,6 +318,7 @@ def atomic_ffmpeg_encode(
295
318
  final_dest: str,
296
319
  retry_without_artwork: bool = True,
297
320
  finalize: Callable[[str], None] | None = None,
321
+ strict: bool = True,
298
322
  ) -> int:
299
323
  """
300
324
  Run FFmpeg with atomic output (write to temp, then rename).
@@ -306,9 +330,12 @@ def atomic_ffmpeg_encode(
306
330
  failure points at the attached picture stream
307
331
  finalize: Optional callable run on the finished temp file before
308
332
  the rename (used to copy extra tags)
333
+ strict: If True, a decode error reported on stderr fails the encode
334
+ and the result is DECODE_ERROR_RC. False for the tolerant retry.
309
335
 
310
336
  Returns:
311
- Return code (0 for success). No output is written on failure.
337
+ Return code (0 for success, DECODE_ERROR_RC when the source did not
338
+ decode cleanly). No output is written on failure.
312
339
  """
313
340
  final_dest = nfc_path(final_dest)
314
341
  dest_dir = os.path.dirname(final_dest)
@@ -329,7 +356,7 @@ def atomic_ffmpeg_encode(
329
356
  source = _source_from_cmd(cmd)
330
357
 
331
358
  logger.info("► %s", " ".join(cmd))
332
- rc, stderr = _run_ffmpeg(cmd)
359
+ rc, stderr = _run_ffmpeg(cmd, strict)
333
360
 
334
361
  if rc != 0 and retry_without_artwork and _is_artwork_error(stderr):
335
362
  _cleanup_temp(tmp_dest)
@@ -337,7 +364,7 @@ def atomic_ffmpeg_encode(
337
364
  cmd = _remove_artwork_from_command(cmd)
338
365
  cmd[-1] = tmp_dest
339
366
  logger.info("► (retry) %s", " ".join(cmd))
340
- rc, stderr = _run_ffmpeg(cmd)
367
+ rc, stderr = _run_ffmpeg(cmd, strict)
341
368
 
342
369
  if rc != 0:
343
370
  detail = _decode_error(stderr) or (stderr.strip().splitlines() or [""])[-1]
@@ -65,6 +65,9 @@ def main() -> int:
65
65
  output.path,
66
66
  )
67
67
 
68
+ if config.replaygain:
69
+ logger.info("ReplayGain: sources and outputs get track gain tags")
70
+
68
71
  # Perform initial sync
69
72
  initial_sync(config)
70
73
 
@@ -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: