Skip to content

Commit 46730b4

Browse files
authored
Merge pull request #528 from TheCaptain989/lidarr-flac2mp3
Lidarr: flac2mp3 Release 2.2
2 parents 2a2faa2 + ec89327 commit 46730b4

8 files changed

Lines changed: 318 additions & 103 deletions

File tree

.assets/lidarr-synology-2.png

17.2 KB
Loading

.assets/lidarr-synology.png

-821 Bytes
Loading

README.md

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# About
2-
A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.io Lidarr Docker container that uses ffmpeg and a script to automatically convert downloaded FLAC files to MP3s. Default output quality is 320Kbps constant bit rate.
2+
A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.io Lidarr Docker container that uses ffmpeg and a script to automatically convert downloaded FLAC (or other format) files to MP3s. Default output quality is 320Kbps constant bit rate.
33
Advanced options act as a light wrapper to ffmpeg, allowing conversion to any supported audio format, including AAC, AC3, Opus, and many others.
44
A [Batch Mode](./README.md#batch-mode) is also supported that allows usage outside of Lidarr.
55

@@ -17,7 +17,7 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
1717
2. Configure the Docker container with all the port, volume, and environment settings from the *original container documentation* here:
1818
**[linuxserver/lidarr](https://hub.docker.com/r/linuxserver/lidarr "Docker container")**
1919
1. Add a **DOCKER_MODS** environment variable to the `docker run` command, as follows:
20-
- Dev/test release: `-e DOCKER_MODS=thecaptain989/lidarr-flac2mp3:latest`
20+
- Dev/test release: `-e DOCKER_MODS=thecaptain989/lidarr-flac2mp3:latest`
2121
- Stable release: `-e DOCKER_MODS=linuxserver/mods:lidarr-flac2mp3`
2222

2323
*Example Docker CLI Configuration*
@@ -49,25 +49,24 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
4949
5050
This will use the defaults to create a 320Kbps MP3 file.
5151
52-
*For any other setting, you **must** either use one of the [included wrapper scripts](./README.md#included-wrapper-scripts) or create a custom script with the command line options you desire. See the [Syntax](./README.md#syntax) section below.*
52+
*For any other setting, you **must** use one of the supported methods to pass arguments to the script. See the [Syntax](./README.md#syntax) section below.*
5353
5454
## Usage
55-
New file(s) with will be placed in the same directory as the original FLAC file(s) (unless redirected with the `--output` option below) and have the same owner and permissions. Existing files with the same track name will be overwritten.
55+
New file(s) will be placed in the same directory as the original FLAC file(s) (unless redirected with the `--output` option below) and have the same owner and permissions. Existing files with the same track name will be overwritten.
5656
5757
By default, if you've configured Lidarr's **Recycle Bin** path correctly, the original audio file will be moved there.
58-
![danger] **NOTE:** If you have *not* configured the Recycle Bin, the original FLAC audio file(s) will be deleted and permanently lost. This behavior may be modifed with the `--keep-file` option.
58+
![danger] **NOTE:** If you have *not* configured the Recycle Bin, the original FLAC audio file(s) will be deleted and permanently lost. This behavior may be modified with the `--keep-file` option.
5959
6060
### Syntax
61-
>**Note:** The **Arguments** field for Custom Scripts was removed in Lidarr release [v0.7.0.1347](https://github.com/lidarr/Lidarr/commit/b9d240924f8965ebb2c5e307e36b810ae076101e "Lidarr commit notes") due to security concerns.
62-
To support options with this version and later, a wrapper script can be manually created that will call *flac2mp3.sh* with the required arguments.
61+
>**Note:** The _Arguments_ field for Custom Scripts was removed in Lidarr release [v0.7.0.1347](https://github.com/lidarr/Lidarr/commit/b9d240924f8965ebb2c5e307e36b810ae076101e "Lidarr commit notes") due to security concerns.
62+
63+
To supply arguments to the script, you **must** either use one of the **[included wrapper scripts](./README.md#included-wrapper-scripts)**, create a **[custom wrapper script](./README.md#example-wrapper-script)**, or set the `FLAC2MP3_ARGS` **[environment variable](./README.md#environment-variable)**.
6364
6465
#### Command Line Options and Arguments
6566
The script may be called with optional command line arguments.
6667
6768
The syntax for the command line is:
68-
`flac2mp3 [OPTIONS] [{-b|--bitrate} <bitrate> | {-v|--quality} <quality> | {-a|--advanced} "<options>" {-e|--extension} <extension>]`
69-
OR
70-
`flac2mp3 [OPTIONS] {-f|--file} <audio_file>`
69+
`flac2mp3 [{-d|--debug} [<level>]] [{-b|--bitrate} <bitrate> | {-v|--quality} <quality> | {-a|--advanced} "<options>" {-e|--extension} <extension>] [{-f|--file} <audio_file>] [{-k|--keepfile}] [{-o|--output} <directory>] [{-r|--regex} '<regex>'] [{-t|--tags} <taglist>]`
7170
7271
Where:
7372
@@ -76,11 +75,13 @@ Option|Argument|Description
7675
-d, --debug|\[\<level\>\]|Enables debug logging. Level is optional.<br/>Default of 1 (low).<br/>2 includes API and FFmpeg output.
7776
-b, --bitrate|\<bitrate\>|Sets the output quality in constant bits per second (CBR).<br/>Examples: 160k, 240k, 300000<br/>**Note:** May not be specified with `-v`, `-a`, or `-e`.
7877
-v, --quality|\<quality\>|Sets the output variable bit rate (VBR).<br/>Specify a value between 0 and 9, with 0 being the highest quality.<br/>See the [FFmpeg MP3 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/MP3) for more details.<br/>**Note:** May not be specified with `-b`, `-a`, or `-e`.
79-
-a, --advanced|\"\<options\>\"|Advanced ffmpeg options.<br/>The specified `options` replace all script defaults and are sent directly to ffmpeg.<br/>The `options` value must be enclosed in quotes.<br/>See [FFmpeg Options](https://ffmpeg.org/ffmpeg.html#Options) for details on valid options, and [Guidelines for high quality audio encoding](https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio) for suggested usage.<br/>**Note:** Requires the `-e` option to also be specified. May not be specified with `-v` or `-b`.<br/>![danger] **WARNING:** You must specify an audio codec (by including a `-c:a <codec>` ffmpeg option) or the resulting file will contain no audio!<br/>![danger] **WARNING:** Invalid `options` could result in script failure!
80-
-e, --extension|\<extension\>|Sets the output file extension<br/>The extension may be prefixed by a dot (".") or not.<br/>**Note:** Requires the `-a` option to also be specified. May not be specified with `-v` or `-b`.
81-
-f, --file|<audio_file>|If included, the script enters **[Batch Mode](./README.md#batch-mode)** and converts the specified audio file.<br/>![danger] **WARNING:** Do not use this argument when called from Lidarr!
78+
-a, --advanced|\"\<options\>\"|Advanced ffmpeg options.<br/>The specified `options` replace all script defaults and are sent directly to ffmpeg.<br/>The `options` value must be enclosed in quotes.<br/>See [FFmpeg Options](https://ffmpeg.org/ffmpeg.html#Options) for details on valid options, and [Guidelines for high quality audio encoding](https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio) for suggested usage.<br/>**Note:** Requires the `-e` option to also be specified. May not be specified with `-v` or `-b`.<br/>![warning] **WARNING:** You must specify an audio codec (by including a `-c:a <codec>` ffmpeg option) or the resulting file will contain no audio!<br/>![warning] **WARNING:** Invalid `options` could result in script failure!
79+
-e, --extension|\<extension\>|Sets the output file extension.<br/>The extension may be prefixed by a dot (".") or not.<br/>Example: .ogg<br/>**Note:** Requires the `-a` option to also be specified. May not be specified with `-v` or `-b`.
80+
-f, --file|<audio_file>|If included, the script enters **[Batch Mode](./README.md#batch-mode)** and converts the specified audio file.<br/>![warning] **WARNING:** Do not use this argument when called from Lidarr!
8281
-o, --output|\<directory\>|Converted audio file(s) are saved to `directory` instead of being located in the same directory as the source audio file.<br/>The path will be created if it does not exist.
8382
-k, --keep-file| |Do not delete the source file or move it to the Lidarr Recycle bin.<br/>**Note:** This also disables triggering a Lidarr rescan after conversion.
83+
-r, --regex|'\<regex\>'|Sets the regular expression used to select input files.<br/>The `regex` value should be enclosed in single quotes and escaped properly.<br/>Defaults to `"\.flac$"`.
84+
-t, --tags|\<taglist\>|Comma separated list of metadata tags to apply automated corrections to.<br/>See [Metadata Corrections](./README.md#metadata-corrections) section.
8485
--help| |Display help and exit.
8586
--version| |Display version and exit.
8687
@@ -91,28 +92,42 @@ The `-a` option effectively makes the script a generic wrapper for ffmpeg. FFmp
9192
9293
The exact format of the executed ffmpeg command is:
9394
```
94-
ffmpeg -loglevel error -i "input.flac" ${options} "output.${extension}"
95+
ffmpeg -loglevel error -nostdin -i "input.flac" ${options} "output.${extension}"
96+
```
97+
98+
#### Technical notes on regex
99+
By default, the script only matches and interacts with FLAC files (specifically, files ending in ".flac"). The `-r` option allows the script to match on a user specified regular expression (i.e. "regex") pattern.
100+
101+
Files are passed to the script with the full Linux path intact. (Ex: `/path/to/audio/a-ha/Hunting High and Low/01 Take on Me.mp3`). Craft your regex with this in mind.
102+
103+
![warning] **NOTE:** Escaping special regex characters (like a dot `.`) requires a double backslash, _even when single quoted!_ This is because **awk** (the program that processes audio files in the script) in most cases [strips a single backslash](https://www.gnu.org/software/gawk/manual/html_node/Escape-Sequences.html "GNU awk reference") from strings. Double quoted or unquoted strings require _four_ backslashes to preserve a regex escape because the bash shell will process the escapes first.
104+
105+
For example, to convert all audio files to AAC audio files, use the following options:
106+
```
107+
-a "-y -map 0 -c:a aac -b:a 240k -c:v copy" -e m4a --regex '\\.[^.]*$'
95108
```
96109
110+
Regular expression syntax is beyond the scope of this document. See this [tutorial](https://www.regular-expressions.info/tutorial.html "Regular Expressions Tutorial") for more information. Regex patterns may be tested [here](http://regexstorm.net/tester "regex tester").
111+
97112
### Examples
98113
```
99114
-b 320k # Output 320 kbit/s MP3 (non-VBR; same as default behavior)
100115
-v 0 # Output variable bitrate MP3, VBR 220-260 kbit/s
101116
-d -b 160k # Enable debugging level 1, and output a 160 kbit/s MP3
117+
-r '\\.[^.]*$' # Convert any file to MP3 (not just FLAC)
102118
-a "-c:v libtheora -map 0 -q:v 10 -c:a libopus -b:a 192k" -e .opus
103-
# Convert to Opus format, VBR 192 kbit/s, cover art, no overwright
119+
# Convert to Opus format, 192 kbit/s, cover art
120+
-a "-vn -c:a libopus -b:a 192K" -e .opus -r '\.mp3$'
121+
# Convert .mp3 files to Opus format, 192 kbit/s, no cover art
104122
-a "-y -map 0 -c:a aac -b:a 240k -c:v copy" -e mp4
105123
# Convert to MP4 format, using AAC 240 kbit/s audio, cover art, overwrite file
106124
--file "/path/to/audio/a-ha/Hunting High and Low/01 Take on Me.flac"
107125
# Batch Mode
108126
# Output 320kbit/s MP3
109127
-o "/path/to/audio" -k
110-
# Place the converted file(s) in the specified directory and do not delete the original audio file(s).
128+
# Place the converted file(s) in the specified directory and do not delete the original audio file(s)
111129
```
112130
113-
### Wrapper Scripts
114-
To supply arguments to the script, one of the included wrapper scripts may be used or a custom wrapper script must be created.
115-
116131
#### Included Wrapper Scripts
117132
For your convenience, several wrapper scripts are included in the `/usr/local/bin/` directory.
118133
You may use any of these scripts in place of the `flac2mp3.sh` mentioned in the [Installation](./README.md#installation) section above.
@@ -141,6 +156,26 @@ Then put `/config/flac2mp3-custom.sh` in the **Path** field in place of `/usr/lo
141156
142157
>**Note:** If you followed the Linuxserver.io recommendations when configuring your container, the `/config` directory will be mapped to an external storage location. It is therefore recommended to place custom scripts in the `/config` directory so they will survive container updates, but they may be placed anywhere that is accessible by Lidarr.
143158
159+
### Environment Variable
160+
The `flac2mp3.sh` script also allows the use of arguments provided by the `FLAC2MP3_ARGS` environment variable. This allows advanced use cases without having to provide a custom script.
161+
162+
For example, the following value would convert any .mp3 to Opus:
163+
```
164+
-e FLAC2MP3_ARGS='-a "-vn -c:a libopus -b:a 192k" -e .opus -r "\\.mp3$"'
165+
```
166+
167+
Make sure to correctly use quotes and/or escape special characters when using this method. (See [regex notes](./README.md#technical-notes-on-regex) above.)
168+
In Docker Compose, the previous command would need an extra `$` to match the end-of-line:
169+
```yaml
170+
environment:
171+
- FLAC2MP3_ARGS=-a "-vn -c:a libopus -b:a 192k" -e .opus -r '\\.mp3$$'
172+
```
173+
174+
*Example Synology Configuration*
175+
![flac2mp3](.assets/lidarr-synology-2.png "Synology container settings")
176+
177+
>**NOTE:** The environment variable settings are _only_ used when **no** command line arguments are present. **Any** command line argument will disable the use of the environment variable.
178+
144179
### Triggers
145180
The only events/notification triggers that are supported are **On Release Import** and **On Upgrade**
146181
@@ -171,6 +206,21 @@ This log can be downloaded from Lidarr under *System* > *Log Files*
171206
Log rotation is performed, with 5 log files of 1MB each kept, matching Lidarr's log retention.
172207
>![danger] **NOTE:** If debug logging is enabled with a level above 1, the log file can grow very large very quickly and is much more likely to be rotated. *Do not leave high-level debug logging enabled permanently.*
173208

209+
#### Metadata Corrections
210+
This feature is not meant for general purpose use. It is only documented for completeness.
211+
212+
List of supported tags and metadata corrections that are applied:
213+
214+
|Tag|Original|Correction
215+
|---|---|---
216+
|disc|1|1/1
217+
|genre|/Pop/|"Pop"
218+
| |/Indie/|"Alternative & Indie"
219+
| |/Industrial/|"Industrial Rock"
220+
| |/Electronic/|"Electronica & Dance"
221+
| |/Punk\|Alternative/|"Alternative & Punk"
222+
| |/Rock/|"Rock"
223+
174224
## Credits
175225
This would not be possible without the following:
176226

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Only the latest major and minor version are supported.
66

77
| Version | Supported |
88
| ------- | ------------------ |
9-
| 2.0.x | :heavy_check_mark: |
10-
| < 2.0 | :x: |
9+
| 2.2.x | :heavy_check_mark: |
10+
| < 2.2 | :x: |
1111

1212
## Reporting a Vulnerability
1313

root/etc/cont-init.d/98-flac2mp3

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ if [ ! -x /usr/local/bin/flac2mp3.sh ]; then
4444
echo "Making scripts executable."
4545
chmod +x /usr/local/bin/flac2*.sh
4646
fi
47-

root/etc/s6-overlay/s6-rc.d/init-mod-lidarr-flac2mp3-add-package/run

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,33 @@ cat <<EOF
44
----------------
55
>>> Flac2MP3 Mod by TheCaptain989 <<<
66
Repos:
7-
Dev/test: https://github.com/TheCaptain989/lidarr-flac2mp3
8-
Prod: https://github.com/linuxserver/docker-mods/tree/lidarr-flac2mp3
7+
Dev/test: https://github.com/TheCaptain989/lidarr-flac2mp3
8+
Prod: https://github.com/linuxserver/docker-mods/tree/lidarr-flac2mp3
99

1010
Version: {{VERSION}}
1111
----------------
1212
EOF
1313

1414
# Determine if setup is needed
1515
if [ ! -f /usr/bin/ffmpeg ]; then
16-
echo "**** Adding ffmpeg to package install list ****"
17-
echo "ffmpeg" >> /mod-repo-packages-to-install.list
16+
echo "**** Adding ffmpeg to package install list ****"
17+
echo "ffmpeg" >> /mod-repo-packages-to-install.list
18+
else
19+
echo "**** flac2mp3 deps already installed, skipping ****"
1820
fi
1921

20-
# Change ownership
21-
if [ $(stat -c '%G' /usr/local/bin/flac2mp3.sh) != "abc" ]; then
22-
echo "Changing ownership on scripts."
23-
chown abc:abc /usr/local/bin/flac2*.sh
24-
fi
25-
26-
# Make executable
27-
if [ ! -x /usr/local/bin/flac2mp3.sh ]; then
28-
echo "Making scripts executable."
29-
chmod +x /usr/local/bin/flac2*.sh
30-
fi
22+
# Check ownership and attributes on each script file
23+
for file in /usr/local/bin/flac2mp3*.sh
24+
do
25+
# Change ownership
26+
if [ $(stat -c '%G' $file) != "abc" ]; then
27+
echo "Changing ownership on $file script."
28+
chown abc:abc $file
29+
fi
3130

31+
# Make executable
32+
if [ ! -x $file ]; then
33+
echo "Making $file script executable."
34+
chmod +x $file
35+
fi
36+
done
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
. /usr/local/bin/flac2mp3.sh --tags disc,genre

0 commit comments

Comments
 (0)