diff --git a/README.md b/README.md index a9c7c9a..c61f41d 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Where: Option|Argument|Description ---|---|--- --d, --debug|\[\\]|Enables debug logging. Level is optional.
Default of 1 (low).
2 includes JSON output. +-d, --debug|\[\\]|Enables debug logging. Level is optional.
Default of 1 (low).
2 includes API and FFmpeg output. -b, --bitrate|\|Sets the output quality in constant bits per second (CBR).
Examples: 160k, 240k, 300000
**Note:** May not be specified with `-v`, `-a`, or `-e`. -v, --quality|\|Sets the output variable bit rate (VBR).
Specify a value between 0 and 9, with 0 being the highest quality.
See the [FFmpeg MP3 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/MP3) for more details.
**Note:** May not be specified with `-b`, `-a`, or `-e`. -a, --advanced|\"\\"|Advanced ffmpeg options.
The specified `options` replace all script defaults and are sent directly to ffmpeg.
The `options` value must be enclosed in quotes.
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.
**Note:** Requires the `-e` option to also be specified. May not be specified with `-v` or `-b`.
![danger] **WARNING:** You must specify an audio codec (by including a `-c:a ` ffmpeg option) or the resulting file will contain no audio!
![danger] **WARNING:** Invalid `options` could result in script failure! @@ -169,7 +169,7 @@ A log file is created for the script activity called: This log can be downloaded from Lidarr under *System* > *Log Files* Log rotation is performed, with 5 log files of 1MB each kept, matching Lidarr's log retention. ->![danger] **NOTE:** If debug logging is enabled with a level above 1, the log file can grow very large very quickly. *Do not leave high-level debug logging enabled permanently.* +>![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.* ## Credits This would not be possible without the following: diff --git a/root/usr/local/bin/flac2mp3.sh b/root/usr/local/bin/flac2mp3.sh index 3b215af..f95fef8 100644 --- a/root/usr/local/bin/flac2mp3.sh +++ b/root/usr/local/bin/flac2mp3.sh @@ -292,7 +292,8 @@ function rescan { echo "$flac2mp3_message" | log [ $flac2mp3_debug -ge 1 ] && echo "Debug|Forcing rescan of artist '$lidarr_artist_id'. Calling Lidarr API 'RefreshArtist' using POST and URL '$flac2mp3_api_url/command'" | log flac2mp3_result=$(curl -s -H "X-Api-Key: $flac2mp3_apikey" \ - -d "{\"name\": 'RefreshArtist', \"artistId\": $lidarr_artist_id}" \ + -H "Content-Type: application/json" \ + -d "{\"name\": \"RefreshArtist\", \"artistId\": $lidarr_artist_id}" \ -X POST "$flac2mp3_api_url/command") [ $flac2mp3_debug -ge 2 ] && echo "API returned: $flac2mp3_result" | awk '{print "Debug|"$0}' | log flac2mp3_jobid="$(echo $flac2mp3_result | jq -crM .id)" @@ -309,6 +310,7 @@ function check_rescan { for ((i=1; i <= 15; i++)); do [ $flac2mp3_debug -ge 1 ] && echo "Debug|Checking job $flac2mp3_jobid completion, try #$i. Calling Lidarr API using GET and URL '$flac2mp3_api_url/command/$flac2mp3_jobid'" | log flac2mp3_result=$(curl -s -H "X-Api-Key: $flac2mp3_apikey" \ + -H "Content-Type: application/json" \ -X GET "$flac2mp3_api_url/command/$flac2mp3_jobid") [ $flac2mp3_debug -ge 2 ] && echo "API returned: $flac2mp3_result" | awk '{print "Debug|"$0}' | log if [ "$(echo $flac2mp3_result | jq -crM .status)" = "completed" ]; then @@ -373,6 +375,7 @@ elif [ -f "$flac2mp3_config" ]; then # Check Lidarr version [ $flac2mp3_debug -ge 1 ] && echo "Debug|Getting Lidarr version. Calling Lidarr API using GET and URL '$flac2mp3_api_url/system/status'" | log flac2mp3_result=$(curl -s -H "X-Api-Key: $flac2mp3_apikey" \ + -H "Content-Type: application/json" \ -X GET "$flac2mp3_api_url/system/status") flac2mp3_return=$?; [ "$flac2mp3_return" != 0 ] && { flac2mp3_message="Error|[$flac2mp3_return] curl error when parsing: \"$flac2mp3_api_url/system/status\"" @@ -386,6 +389,7 @@ elif [ -f "$flac2mp3_config" ]; then # Get RecycleBin [ $flac2mp3_debug -ge 1 ] && echo "Debug|Getting Lidarr RecycleBin. Calling Lidarr API using GET and URL '$flac2mp3_api_url/config/mediamanagement'" | log flac2mp3_result=$(curl -s -H "X-Api-Key: $flac2mp3_apikey" \ + -H "Content-Type: application/json" \ -X GET "$flac2mp3_api_url/config/mediamanagement") flac2mp3_return=$?; [ "$flac2mp3_return" != 0 ] && { flac2mp3_message="Error|[$flac2mp3_return] curl error when parsing: \"$flac2mp3_api_url/v3/config/mediamanagement\"" @@ -467,6 +471,9 @@ BEGIN { RS="|" IGNORECASE=1 if (EXT == "") EXT=".mp3" + if (Debug == 0) FFmpegLOG="error" + else if (Debug == 1) FFmpegLOG="warning" + else if (Debug >= 2) FFmpegLOG="info" if (Bitrate) { if (Debug >= 1) print "Debug|Using constant bitrate of "Bitrate BrCommand="-b:a "Bitrate @@ -489,8 +496,9 @@ BEGIN { if (FFmpegADV) FFmpegOPTS=FFmpegADV else FFmpegOPTS="-c:v copy -map 0 -y -acodec libmp3lame "BrCommand" -write_id3v1 1 -id3v2_version 3" # Convert the track - if (Debug >= 1) print "Debug|Executing: nice "FFmpeg" -loglevel error -i \""Track"\" "FFmpegOPTS" \""NewTrack"\"" - Result=system("nice "FFmpeg" -loglevel error -i \""Track"\" "FFmpegOPTS" \""NewTrack"\" 2>&1") + if (Debug >= 1) print "Debug|Executing: nice "FFmpeg" -loglevel "FFmpegLOG" -nostdin -i \""Track"\" "FFmpegOPTS" \""NewTrack"\"" + Result=system("nice "FFmpeg" -loglevel "FFmpegLOG" -nostdin -i \""Track"\" "FFmpegOPTS" \""NewTrack"\" 2>&1") + if (Debug >= 2) print "Debug|ffmpeg exited" if (Result) { print "Error|Exit code "Result" converting \""Track"\"" } else { @@ -523,6 +531,7 @@ BEGIN { # Check for awk script completion flac2mp3_return="${PIPESTATUS[1]}" # captures awk exit status +[ $flac2mp3_debug -ge 2 ] && echo "Debug|awk exited with code: $flac2mp3_return" | log if [ "$flac2mp3_return" != 0 ]; then flac2mp3_message="Error|[$flac2mp3_return] Script exited abnormally. File permissions issue?" echo "$flac2mp3_message" | log