1.0.0031 - Add Audio Format and Bitrate Options

Enables conversion to desired Audio Format (opus/mp3/aac/alac) with the desired bitrate. Also enables downloading in native download client format.
pull/6/head
RandomNinjaAtk 2 years ago committed by GitHub
parent 32af208f4d
commit 6306d4d7a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,10 +14,12 @@ CountryCode=US
# Debugging settings # Debugging settings
#dlClientSource=deezer #dlClientSource=deezer
#topLimit=25 #topLimit=25
#addDeezerTopArtists=true #addDeezerTopArtists=false
#addDeezerTopAlbumArtists=true #addDeezerTopAlbumArtists=false
#addDeezerTopTrackArtists=true #addDeezerTopTrackArtists=false
#configureLidarrWithOptimalSettings=true #configureLidarrWithOptimalSettings=false
#audioFormat=opus
#audioBitrate=160
log () { log () {
m_time=`date "+%F %T"` m_time=`date "+%F %T"`
@ -36,7 +38,7 @@ Configuration () {
log "" log ""
sleep 2 sleep 2
log "############# $dockerTitle" log "############# $dockerTitle"
log "############# SCRIPT VERSION 1.0.0030" log "############# SCRIPT VERSION 1.0.0031"
log "############# DOCKER VERSION $dockerVersion" log "############# DOCKER VERSION $dockerVersion"
if [ -z $topLimit ]; then if [ -z $topLimit ]; then
@ -74,10 +76,32 @@ Configuration () {
else else
log ":: Configure Lidarr with optimal settings is disabled (enable by setting configureLidarrWithOptimalSettings=true)" log ":: Configure Lidarr with optimal settings is disabled (enable by setting configureLidarrWithOptimalSettings=true)"
fi fi
}
log ":: Output format = $audioFormat"
log ":: Output bitrate = $audioBitrate"
}
DownloadFormat () {
if [ $audioFormat = native ]; then
if [ $audioBitrate = lossless ]; then
tidal-dl -q HiFi
deemixQuality=flac
elif [ $audioBitrate = high ]; then
tidal-dl -q High
deemixQuality=320
elif [ $audioBitrate = low ]; then
tidal-dl -q Normal
deemixQuality=128
else
log ":: ERROR :: Invalid quality options set..."
log ":: ERROR :: Exiting..."
exit
fi
else
tidal-dl -q HiFi
deemixQuality=flac
fi
}
AddDeezerTopArtists () { AddDeezerTopArtists () {
getDeezerArtistsIds=($(curl -s "https://api.deezer.com/chart/0/artists?limit=$1" | jq -r ".data[].id")) getDeezerArtistsIds=($(curl -s "https://api.deezer.com/chart/0/artists?limit=$1" | jq -r ".data[].id"))
@ -254,7 +278,6 @@ TidalClientSetup () {
fi fi
tidal-dl -o /downloads/lidarr-extended/incomplete tidal-dl -o /downloads/lidarr-extended/incomplete
tidal-dl -r P1080 tidal-dl -r P1080
tidal-dl -q HiFi
fi fi
# check for backup token and use it if exists # check for backup token and use it if exists
@ -338,7 +361,7 @@ DownloadProcess () {
fi fi
if [ "$2" = "DEEZER" ]; then if [ "$2" = "DEEZER" ]; then
deemix -b flac -p /downloads/lidarr-extended/incomplete "https://www.deezer.com/us/album/$1" deemix -b $deemixQuality -p /downloads/lidarr-extended/incomplete "https://www.deezer.com/us/album/$1"
if [ -d "/tmp/deemix-imgs" ]; then if [ -d "/tmp/deemix-imgs" ]; then
rm -rf /tmp/deemix-imgs rm -rf /tmp/deemix-imgs
fi fi
@ -360,6 +383,44 @@ DownloadProcess () {
return return
fi fi
if [ audioFormat != native ]; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Converting Flac Audio to ${audioFormat^^} ${audioBitrate}k"
if [ $audioFormat = opus ]; then
options="-acodec libopus -ab ${audioBitrate}k -application audio -vbr off"
extension="opus"
fi
if [ $audioFormat = mp3 ]; then
options="-acodec libmp3lame -ab ${audioBitrate}k"
extension="mp3"
fi
if [ $audioFormat = aac ]; then
options="-c:a libfdk_aac -b:a ${audioBitrate}k -movflags faststart"
extension="m4a"
fi
if [ $audioFormat = alac ]; then
options="-c:a alac -movflags faststart"
extension="m4a"
fi
find "/downloads/lidarr-extended/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' audio; do
file="${audio}"
filename="$(basename "$audio")"
foldername="$(dirname "$audio")"
filenamenoext="${filename%.*}"
if ffmpeg -loglevel warning -hide_banner -nostats -i "$file" -n -vn $options "$foldername/${filenamenoext}.$extension" < /dev/null; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $filename :: Conversion to $audioFormat (${audioBitrate}k) successful"
rm "$file"
else
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $filename :: ERROR :: Conversion Failed"
rm "$foldername/${filenamenoext}.$extension"
fi
done
fi
albumquality="$(find /downloads/lidarr-extended/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | egrep -i -E -o "\.{1}\w*$" | sed 's/\.//g')" albumquality="$(find /downloads/lidarr-extended/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | egrep -i -E -o "\.{1}\w*$" | sed 's/\.//g')"
downloadedAlbumFolder="$lidarrArtistNameSanitized-$downloadedAlbumTitleClean ($3)-${albumquality^^}-$2" downloadedAlbumFolder="$lidarrArtistNameSanitized-$downloadedAlbumTitleClean ($3)-${albumquality^^}-$2"
@ -820,15 +881,29 @@ ProcessWithBeets () {
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: BEETS MATCH FOUND!" log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: BEETS MATCH FOUND!"
fi fi
GetFile=$(find "$1" -type f -iname "*.flac" | head -n1) GetFile=$(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n1)
if [ $albumquality = opus ]; then
matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".streams[].tags")
else
matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".format.tags") matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".format.tags")
fi
if [ $albumquality = flac ] || [ $albumquality = opus ]; then
matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_RELEASEGROUPID")" matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_RELEASEGROUPID")"
matchedTagsAlbumTitle="$(echo $matchedTags | jq -r ".ALBUM")" elif [ $albumquality = mp3 ] || [ $albumquality = m4a ]; then
matchedTagsAlbumTitleClean="$(echo "$matchedTagsAlbumTitle" | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')" matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r '."MusicBrainz Release Group Id"')"
matchedTagsAlbumArtist="$(echo $matchedTags | jq -r ".album_artist")" fi
matchedTagsAlbumYear="$(echo $matchedTags | jq -r ".YEAR")" if [ $albumquality = m4a ]; then
matchedTagsAlbumType="$(echo $matchedTags | jq -r ".RELEASETYPE")" if [ $audioFormat = alac ]; then
albumquality=alac
else
albumquality=aac
fi
fi
matchedLidarrAlbumData=$(curl -s "$lidarrUrl/api/v1/search?term=lidarr%3A$matchedTagsAlbumReleaseGroupId" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[].album") matchedLidarrAlbumData=$(curl -s "$lidarrUrl/api/v1/search?term=lidarr%3A$matchedTagsAlbumReleaseGroupId" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[].album")
matchedTagsAlbumTitle="$(echo $matchedLidarrAlbumData | jq -r ".title")"
matchedTagsAlbumTitleClean="$(echo "$matchedTagsAlbumTitle" | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
matchedTagsAlbumReleaseDate="$(echo $matchedLidarrAlbumData | jq -r ".releaseDate")"
matchedTagsAlbumYear="${matchedTagsAlbumReleaseDate:0:4}"
matchedLidarrAlbumArtistId="$(echo "$matchedLidarrAlbumData" | jq -r ".artist.foreignArtistId")" matchedLidarrAlbumArtistId="$(echo "$matchedLidarrAlbumData" | jq -r ".artist.foreignArtistId")"
matchedLidarrAlbumArtistName="$(echo "$matchedLidarrAlbumData" | jq -r ".artist.artistName")" matchedLidarrAlbumArtistName="$(echo "$matchedLidarrAlbumData" | jq -r ".artist.artistName")"
matchedLidarrAlbumArtistCleanName="$(echo "$matchedLidarrAlbumData" | jq -r ".artist.cleanName")" matchedLidarrAlbumArtistCleanName="$(echo "$matchedLidarrAlbumData" | jq -r ".artist.cleanName")"
@ -877,7 +952,7 @@ ProcessWithBeets () {
matchedLidarrAlbumArtistCleanName="$(echo "$matchedLidarrAlbumArtistName" | sed -e "s%[^[:alpha:][:digit:]._()' -]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')" matchedLidarrAlbumArtistCleanName="$(echo "$matchedLidarrAlbumArtistName" | sed -e "s%[^[:alpha:][:digit:]._()' -]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
downloadedAlbumFolder="${matchedLidarrAlbumArtistCleanName}-${matchedTagsAlbumTitleClean} ($matchedTagsAlbumYear)-$2-$3" downloadedAlbumFolder="${matchedLidarrAlbumArtistCleanName}-${matchedTagsAlbumTitleClean} ($matchedTagsAlbumYear)-${albumquality^^}-$3"
if [ "$1" != "/downloads/lidarr-extended/complete/$downloadedAlbumFolder" ];then if [ "$1" != "/downloads/lidarr-extended/complete/$downloadedAlbumFolder" ];then
mv "$1" "/downloads/lidarr-extended/complete/$downloadedAlbumFolder" mv "$1" "/downloads/lidarr-extended/complete/$downloadedAlbumFolder"
chmod 777 "/downloads/lidarr-extended/complete/$downloadedAlbumFolder" chmod 777 "/downloads/lidarr-extended/complete/$downloadedAlbumFolder"
@ -968,6 +1043,16 @@ fi
LidarrRootFolderCheck LidarrRootFolderCheck
if [ "$dlClientSource" = "deezer" ] || [ "$dlClientSource" = "both" ]; then
DeemixClientSetup
fi
if [ "$dlClientSource" = "tidal" ] || [ "$dlClientSource" = "both" ]; then
TidalClientSetup
fi
DownloadFormat
if [ "$addDeezerTopArtists" = "true" ]; then if [ "$addDeezerTopArtists" = "true" ]; then
AddDeezerTopArtists "$topLimit" AddDeezerTopArtists "$topLimit"
fi fi
@ -984,14 +1069,6 @@ if [ "$addRelatedArtists" = "true" ]; then
AddRelatedArtists AddRelatedArtists
fi fi
if [ "$dlClientSource" = "deezer" ] || [ "$dlClientSource" = "both" ]; then
DeemixClientSetup
fi
if [ "$dlClientSource" = "tidal" ] || [ "$dlClientSource" = "both" ]; then
TidalClientSetup
fi
if [ "$dlClientSource" = "deezer" ] || [ "$dlClientSource" = "tidal" ] || [ "$dlClientSource" = "both" ]; then if [ "$dlClientSource" = "deezer" ] || [ "$dlClientSource" = "tidal" ] || [ "$dlClientSource" = "both" ]; then
GetMissingCutOffList GetMissingCutOffList
SearchProcess SearchProcess

Loading…
Cancel
Save