1.0.013 - Logging Improvements, add processing time calculation...

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

@ -1,5 +1,5 @@
#!/usr/bin/env bash
scriptVersion=1.0.012
scriptVersion=1.0.013
if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then
lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
if [ "$lidarrUrlBase" == "null" ]; then
@ -20,6 +20,7 @@ fi
exec &> >(tee -a "/config/logs/MetadataPostProcess.txt")
touch "/config/logs/MetadataPostProcess.txt"
chmod 666 "/config/logs/MetadataPostProcess.txt"
SECONDS=0
log () {
m_time=`date "+%F %T"`
@ -35,59 +36,72 @@ getAlbumArtist="$(curl -s "$lidarrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-K
getAlbumArtistPath="$(curl -s "$lidarrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${lidarrApiKey}" | jq -r .artist.path)"
getTrackPath="$(curl -s "$lidarrUrl/api/v1/trackFile?albumId=$lidarr_album_id" -H "X-Api-Key: ${lidarrApiKey}" | jq -r .[].path | head -n1)"
getFolderPath="$(dirname "$getTrackPath")"
getAlbumFolderName="$(basename "$getFolderPath")"
log "Processing :: $getAlbumFolderName :: Start"
if echo "$getFolderPath" | grep "$getAlbumArtistPath" | read; then
if [ ! -d "$getFolderPath" ]; then
log "ERROR :: \"$getFolderPath\" Folder is missing :: Exiting..."
log "Processing :: $getAlbumFolderName :: ERROR :: \"$getFolderPath\" Folder is missing :: Exiting..."
exit
fi
else
log "ERROR :: $getAlbumArtistPath not found within \"$getFolderPath\" :: Exiting..."
log "Processing :: $getAlbumFolderName :: ERROR :: $getAlbumArtistPath not found within \"$getFolderPath\" :: Exiting..."
exit
fi
if ls "$getFolderPath" | grep "lrc" | read; then
log "Removing existing lrc files"
log "Processing :: $getAlbumFolderName :: Removing existing lrc files"
find "$getFolderPath" -type f -iname "*.lrc" -delete
fi
find "$getFolderPath" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' file; do
fileName=$(basename -- "$file")
fileExt="${fileName##*.}"
fileNameNoExt="${fileName%.*}"
if [ ! -f "$getFolderPath/folder.jpg" ] && [ ! -f "$getFolderPath/folder.jpeg" ]; then
log "Processing :: $getAlbumFolderName :: $fileName :: Extracting Artwork..."
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"
log "Processing :: $getAlbumFolderName :: Album Artwork Extracted to: $getFolderPath/folder.jpg"
chmod 666 "$getFolderPath/folder.jpg"
fi
fi
if [ "$fileExt" == "flac" ]; then
log "Processing :: $getAlbumFolderName :: $fileName :: Getting Lyrics from embedded metadata"
getLyrics="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.LYRICS" | sed "s/null//g" | sed "/^$/d")"
log "Processing :: $getAlbumFolderName :: $fileName :: Getting ARTIST_CREDIT from embedded metadata"
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
if [ "$fileExt" == "opus" ]; then
log "Processing :: $getAlbumFolderName :: $fileName :: Getting Lyrics from embedded metadata"
getLyrics="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".streams[].tags.LYRICS" | sed "s/null//g" | sed "/^$/d")"
fi
if [ ! -z "$getLyrics" ]; then
lrcFile="${file%.*}.lrc"
log "Processing :: $file :: Extracting Lyrics..."
log "Processing :: $getAlbumFolderName :: $fileName :: Extracting Lyrics..."
echo -n "$getLyrics" > "$lrcFile"
log "Processing :: $file :: Lyrics extracted to: $lrcFile"
log "Processing :: $getAlbumFolderName :: $fileName :: Lyrics extracted to: $fileNameNoExt.lrc"
chmod 666 "$lrcFile"
else
log "Processing :: $getAlbumFolderName :: $fileName :: Lyrics not found..."
fi
if [ "$fileExt" == "flac" ]; then
if [ ! -z "$getArtistCredit" ]; then
log "Processing :: $file :: Setting ARTIST tag to match ARTIST_CREDIT tag..."
log "Processing :: $getAlbumFolderName :: $fileName :: Setting ARTIST tag to match ARTIST_CREDIT tag..."
metaflac --remove-tag=ARTIST "$file"
metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
else
log "Processing :: $getAlbumFolderName :: $fileName :: ARTIST_CREDIT not found..."
fi
fi
done
duration=$SECONDS
log "Processing :: $getAlbumFolderName :: Finished in $(($duration / 60 )) minutes and $(($duration % 60 )) seconds!"
exit

Loading…
Cancel
Save