Skip to content

Commit

Permalink
Release 2.3 (#41)
Browse files Browse the repository at this point in the history
### What's Changed
- **Complete re-write of the core script to use shell instead of AWK.**
- Better use of the Lidarr API, including:
  - Using it to delete or recycle old tracks
  - No more artist refresh/rescan (which took forever)
  - Imports the converted tracks directly
- Fixed logging of curl errors
- Much better error handling
- Removed unnecessary function
- Improved track import JSON generator logic
- Added check for 'queued'  job status
  • Loading branch information
TheCaptain989 authored Aug 26, 2023
1 parent 73f4439 commit 0c09a95
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 308 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/BuildImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ jobs:
- name: Tag image
run: |
docker tag ${ENDPOINT}:${{ github.sha }} ${ENDPOINT}:latest
if [[ "${{ github.ref_name }}" == 'master' ]]; then
IMAGETAG=${ENDPOINT}:latest
else
IMAGETAG=${ENDPOINT}:${{ github.ref_name }}
fi
echo "IMAGETAG=${IMAGETAG}" >> $GITHUB_ENV
docker tag ${ENDPOINT}:${{ github.sha }} ${IMAGETAG}
docker tag ${ENDPOINT}:${{ github.sha }} ghcr.io/${ENDPOINT}:${{ github.sha }}
docker tag ${ENDPOINT}:${{ github.sha }} ghcr.io/${IMAGETAG}
- name: Credential check
run: |
Expand All @@ -40,16 +48,31 @@ jobs:
exit 1
fi
- name: Login to GitHub Container Registry
if: ${{ env.CR_USER && env.CR_PAT }}
run: |
echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.CR_USER }} --password-stdin
- name: Push tags to GitHub Container Registry
if: ${{ env.CR_USER && env.CR_PAT }}
run: |
docker push ghcr.io/${ENDPOINT}:${{ github.sha }}
docker push ghcr.io/${IMAGETAG}
echo "Pushed the following images/tags to GHCR:" >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/${ENDPOINT}:${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/${IMAGETAG}" >> $GITHUB_STEP_SUMMARY
- name: Login to DockerHub
if: ${{ env.DOCKERUSER != '' && env.DOCKERPASS != '' }}
if: ${{ env.DOCKERUSER && env.DOCKERPASS }}
run: |
echo "${{ secrets.DOCKERPASS }}" | docker login -u "${{ secrets.DOCKERUSER }}" --password-stdin
- name: Push tags to DockerHub
if: ${{ env.DOCKERUSER != '' && env.DOCKERPASS != '' }}
if: ${{ env.DOCKERUSER && env.DOCKERPASS }}
run: |
docker push ${ENDPOINT}:${{ github.sha }}
docker push ${ENDPOINT}:latest
docker push ${IMAGETAG}
echo "Pushed the following images/tags to Docker Hub:" >> $GITHUB_STEP_SUMMARY
echo "${ENDPOINT}:${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "${ENDPOINT}:latest" >> $GITHUB_STEP_SUMMARY
echo "${IMAGETAG}" >> $GITHUB_STEP_SUMMARY
16 changes: 0 additions & 16 deletions .github/workflows/call_issue_pr_tracker.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/permissions.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ RUN \
## Single layer deployed image ##
FROM scratch

LABEL org.opencontainers.image.source=https://github.com/TheCaptain989/lidarr-flac2mp3
LABEL org.opencontainers.image.description="A Docker Mod to Lidarr to automatically convert FLAC files to MP3s, or other format"
LABEL org.opencontainers.image.licenses=GPL-3.0-only
LABEL maintainer="TheCaptain989"

# Copy local files
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ A [Batch Mode](./README.md#batch-mode) is also supported that allows usage outsi

>**NOTE:** This mod supports Linux OSes only.
Production Container info: ![Docker Image Size](https://img.shields.io/docker/image-size/linuxserver/mods/lidarr-flac2mp3 "Container Size")
Development Container info:
![Docker Image Size](https://img.shields.io/docker/image-size/thecaptain989/lidarr-flac2mp3 "Container Size")
![Docker Pulls](https://img.shields.io/docker/pulls/thecaptain989/lidarr-flac2mp3 "Container Pulls")
Production Container info: ![Docker Image Size](https://img.shields.io/docker/image-size/linuxserver/mods/lidarr-flac2mp3 "Container Size")
![Docker Pulls](https://img.shields.io/docker/pulls/thecaptain989/lidarr-flac2mp3 "Container Pulls")

# Installation
1. Pull the [linuxserver/lidarr](https://hub.docker.com/r/linuxserver/lidarr "LinuxServer.io's Lidarr container") docker image from Docker Hub:
`docker pull linuxserver/lidarr:latest`
1. Pull the [linuxserver/lidarr](https://hub.docker.com/r/linuxserver/lidarr "LinuxServer.io's Lidarr container") docker image from GitHub Container Registry or Docker Hub:
`docker pull lscr.io/linuxserver/lidarr:latest`

2. Configure the Docker container with all the port, volume, and environment settings from the *original container documentation* here:
**[linuxserver/lidarr](https://hub.docker.com/r/linuxserver/lidarr "Docker container")**
1. Add a **DOCKER_MODS** environment variable to the `docker run` command, as follows:
- Dev/test release: `-e DOCKER_MODS=thecaptain989/lidarr-flac2mp3:latest`
- Stable release: `-e DOCKER_MODS=linuxserver/mods:lidarr-flac2mp3`
- Dev/test release: `-e DOCKER_MODS=thecaptain989/lidarr-flac2mp3:latest`

*Example Docker CLI Configuration*
```shell
Expand All @@ -36,7 +36,7 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
-v /path/to/music:/music \
-v /path/to/downloads:/downloads \
--restart unless-stopped \
ghcr.io/linuxserver/lidarr
lscr.io/linuxserver/lidarr
```

*Example Synology Configuration*
Expand Down Expand Up @@ -75,15 +75,15 @@ Where:
Option|Argument|Description
---|---|---
-d, --debug|\[\<level\>\]|Enables debug logging. Level is optional.<br/>Default of 1 (low).<br/>2 includes API and FFmpeg output.
-d, --debug|\[\<level\>\]|Enables debug logging. Level is optional.<br/>Default of 1 (low).<br/>2 includes JSON and FFmpeg output.<br/>3 contains even more JSON output.
-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`.
-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`.
-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!
-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`.
-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!
-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.
-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.
-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$"`.
-k, --keep-file| |Do not delete the source file or move it to the Lidarr Recycle bin.<br/>**Note:** This also disables importing the new files into Lidarr after conversion.
-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$`.
-t, --tags|\<taglist\>|Comma separated list of metadata tags to apply automated corrections to.<br/>See [Metadata Corrections](./README.md#metadata-corrections) section.
--help| |Display help and exit.
--version| |Display version and exit.
Expand All @@ -103,11 +103,11 @@ By default, the script only matches and interacts with FLAC files (specifically,
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.
![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.
![warning] **NOTE:** Escaping special regex characters (like a dot `.`) requires a double backslash or a character class. A character class (i.e. `[.]`) is recommended because backslashes can be stripped by the bash shell and getting this right can be confusing.
For example, to convert all audio files to AAC audio files, use the following options:
```
-a "-y -map 0 -c:a aac -b:a 240k -c:v copy" -e m4a --regex '\\.[^.]*$'
-a "-y -map 0 -c:a aac -b:a 240k -c:v copy" -e m4a --regex '[.][^.]*$'
```
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").
Expand All @@ -117,13 +117,13 @@ Regular expression syntax is beyond the scope of this document. See this [tutor
-b 320k # Output 320 kbit/s MP3 (non-VBR; same as default behavior)
-v 0 # Output variable bitrate MP3, VBR 220-260 kbit/s
-d -b 160k # Enable debugging level 1, and output a 160 kbit/s MP3
-r '\\.[^.]*$' # Convert any file to MP3 (not just FLAC)
-r '[.][^.]*$' # Convert any file to MP3 (not just FLAC)
-a "-c:v libtheora -map 0 -q:v 10 -c:a libopus -b:a 192k" -e .opus
# Convert to Opus format, 192 kbit/s, cover art
-a "-vn -c:a libopus -b:a 192K" -e .opus -r '\.mp3$'
-a "-vn -c:a libopus -b:a 192K" -e .opus -r '[.]mp3$'
# Convert .mp3 files to Opus format, 192 kbit/s, no cover art
-a "-y -map 0 -c:a aac -b:a 240k -c:v copy" -e mp4
# Convert to MP4 format, using AAC 240 kbit/s audio, cover art, overwrite file
-a "-y -map 0 -c:a aac -b:a 240k -c:v copy" -e m4a
# Convert to M4A format, using AAC 240 kbit/s audio, cover art, overwrite file
--file "/path/to/audio/a-ha/Hunting High and Low/01 Take on Me.flac"
# Batch Mode
# Output 320kbit/s MP3
Expand Down Expand Up @@ -164,14 +164,14 @@ The `flac2mp3.sh` script also allows the use of arguments provided by the `FLAC2
For example, the following value would convert any .mp3 to Opus:
```
-e FLAC2MP3_ARGS='-a "-vn -c:a libopus -b:a 192k" -e .opus -r "\\.mp3$"'
-e FLAC2MP3_ARGS='-a "-vn -c:a libopus -b:a 192k" -e .opus -r "[.]mp3$"'
```
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.)
In Docker Compose, the previous command would need an extra `$` to match the end-of-line:
```yaml
environment:
- FLAC2MP3_ARGS=-a "-vn -c:a libopus -b:a 192k" -e .opus -r '\\.mp3$$'
- FLAC2MP3_ARGS=-a "-vn -c:a libopus -b:a 192k" -e .opus -r '[.]mp3$$'
```
*Example Synology Configuration*
Expand All @@ -190,7 +190,7 @@ Using this function, you can easily process all of your audio files in any subdi
#### Script Execution Differences in Batch Mode
Because the script is not called from within Lidarr, expect the following behavior while in Batch Mode:
* *The file name must be specified on the command line*<br/>(The `-f` option places the script in Batch Mode)
* *Lidarr APIs are not called and its database is not updated.*<br/>This may require a manual rescan of converted music files.
* *Lidarr APIs are not called and its database is not updated.*<br/>This may require a manual import of converted music files or an artist rescan.
* *Original audio files are deleted.*<br/>The Recycle Bin function is not available. (Modifiable using the `-k` option.)
#### Batch Example
Expand Down Expand Up @@ -229,7 +229,7 @@ This would not be possible without the following:

[Lidarr](https://lidarr.audio/ "Lidarr homepage")
[LinuxServer.io Lidarr](https://hub.docker.com/r/linuxserver/lidarr "Lidarr Docker container") container
[LinuxServer.io Docker Mods](https://hub.docker.com/r/linuxserver/mods "Docker Mods containers") project
[LinuxServer.io Docker Mods](https://github.com/linuxserver/docker-mods "Docker Mods containers") project
[ffmpeg](https://ffmpeg.org/ "FFmpeg homepage")
Icons made by [Freepik](https://www.freepik.com) from [Flaticon](https://www.flaticon.com/)

Expand Down
Loading

0 comments on commit 0c09a95

Please sign in to comment.