1.0.011 - Reconfigure overall process

pull/139/head
RandomNinjaAtk 2 years ago committed by GitHub
parent 7a0fc5d37c
commit 18f5ab5bcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
scriptVersion=1.0.010 scriptVersion=1.0.011
if [ -z "$lidarr_artist_path" ]; then if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then
lidarr_artist_path="$1" lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
if [ "$lidarrUrlBase" == "null" ]; then
lidarrUrlBase=""
else
lidarrUrlBase="/$(echo "$lidarrUrlBase" | sed "s/\///g")"
fi
lidarrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)"
lidarrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)"
lidarrUrl="http://127.0.0.1:${lidarrPort}${lidarrUrlBase}"
fi fi
# auto-clean up log file to reduce space usage # auto-clean up log file to reduce space usage
@ -23,49 +31,63 @@ if [ "$lidarr_eventtype" == "Test" ]; then
exit 0 exit 0
fi fi
log "Processing :: $lidarr_trackfile_path" getAlbumArtist="$(curl -s "$lidarrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${lidarrApiKey}" | jq -r .artist.artistName)"
albumFolder=$(dirname "$lidarr_trackfile_path") getAlbumArtistPath="$(curl -s "$lidarrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${lidarrApiKey}" | jq -r .artist.path)"
if [ -d "$albumFolder" ]; then getTrackPath="$(curl -s "$lidarrUrl/api/v1/trackFile?albumId=$lidarr_album_id" -H "X-Api-Key: ${lidarrApiKey}" | jq -r .[].path | head -n1)"
if [ ! -f "$albumFolder/folder.jpg" ]; then getFolderPath="$(dirname "$getTrackPath")"
ffmpeg -i "$lidarr_trackfile_path" -an -vcodec copy "$albumFolder/folder.jpg" &> /dev/null
if [ -f "$albumFolder/folder.jpg" ]; then if echo "$getFolderPath" | grep "$getAlbumArtistPath" | read; then
log "Processing :: $albumFolder :: Album Artwork Extracted to: $albumFolder/folder.jpg" if [ ! -d "$getFolderPath" ]; then
chmod 666 "$albumFolder/folder.jpg" log "ERROR :: \"$getFolderPath\" Folder is missing :: Exiting..."
fi exit
fi fi
else else
log "Processing :: ERROR :: $albumFolder :: folder missing..." log "ERROR :: $getAlbumArtistPath not found within \"$getFolderPath\" :: Exiting..."
exit
fi fi
lrcFile="${lidarr_trackfile_path%.*}.lrc" find "$getFolderPath" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' file; do
if [ -f "$lrcFile" ]; then fileName=$(basename -- "$file")
rm "$lrcFile"
fi
fileName=$(basename -- "$lidarr_trackfile_path")
fileExt="${fileName##*.}" fileExt="${fileName##*.}"
if [ ! -f "$getFolderPath/folder.jpg" ] && [ ! -f "$getFolderPath/folder.jpeg" ]; then
ffmpeg -i "$file" -an -vcodec copy "$getFolderPath/folder.jpg" &> /dev/null
if [ -f "$getFolderPath/folder.jpg" ] && [ -f "$getFolderPath/folder.jpeg" ]; then
log "Processing :: $getFolderPath :: Album Artwork Extracted to: $getFolderPath/folder.jpg"
chmod 666 "$getFolderPath/folder.jpg"
fi
fi
if ls "$getFolderPath" | grep "lrc" | read; then
log "Removing existing lrc files"
find "$getFolderPath" -type f -iname "*.lrc" -delete
fi
if [ "$fileExt" == "flac" ]; then if [ "$fileExt" == "flac" ]; then
getLyrics="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$lidarr_trackfile_path" | jq -r ".format.tags.LYRICS" | sed "s/null//g" | sed "/^$/d")" getLyrics="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.LYRICS" | sed "s/null//g" | sed "/^$/d")"
getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$lidarr_trackfile_path" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")" getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")"
fi fi
if [ "$fileExt" == "opus" ]; then if [ "$fileExt" == "opus" ]; then
getLyrics="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$lidarr_trackfile_path" | jq -r ".streams[].tags.LYRICS" | sed "s/null//g" | sed "/^$/d")" getLyrics="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".streams[].tags.LYRICS" | sed "s/null//g" | sed "/^$/d")"
fi fi
if [ ! -z "$getLyrics" ]; then if [ ! -z "$getLyrics" ]; then
log "Processing :: $lidarr_trackfile_path :: Extracting Lyrics..." lrcFile="${file%.*}.lrc"
log "Processing :: $file :: Extracting Lyrics..."
echo -n "$getLyrics" > "$lrcFile" echo -n "$getLyrics" > "$lrcFile"
log "Processing :: $lidarr_trackfile_path :: Lyrics extracted to: $lrcFile" log "Processing :: $file :: Lyrics extracted to: $lrcFile"
chmod 666 "$lrcFile" chmod 666 "$lrcFile"
fi fi
if [ "$fileExt" == "flac" ]; then if [ "$fileExt" == "flac" ]; then
if [ ! -z "$getArtistCredit" ]; then if [ ! -z "$getArtistCredit" ]; then
log "Processing :: $lidarr_trackfile_path :: Setting ARTIST tag to match ARTIST_CREDIT tag..." log "Processing :: $file :: Setting ARTIST tag to match ARTIST_CREDIT tag..."
metaflac --remove-tag=ARTIST "$lidarr_trackfile_path" metaflac --remove-tag=ARTIST "$file"
metaflac --set-tag=ARTIST="$getArtistCredit" "$lidarr_trackfile_path" metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
fi fi
fi fi
done
exit exit

Loading…
Cancel
Save