diff --git a/sabnzbd/audiobook.bash b/sabnzbd/audiobook.bash index 1fdd4d0..fa9dec0 100644 --- a/sabnzbd/audiobook.bash +++ b/sabnzbd/audiobook.bash @@ -1,5 +1,5 @@ #!/usr/bin/with-contenv bash -ScriptVersion="0.5" +ScriptVersion="1.0" scriptName="Audiobook" #### Import Settings @@ -21,14 +21,17 @@ exec &> >(tee -a "/config/scripts/audiobook.txt") SECONDS=0 -log "Searching for audiobook (m4b) files in \"$1\"..." +log "Searching for audiobook (m4b) files in completed download..." if [ $(find "$1" -type f -iname "*.m4b" | wc -l) -gt 0 ]; then log "M4B files found, removing non m4b files..." find "$1" -type f -not -iname "*.m4b" -delete find "$1" -mindepth 2 -type f -exec mv "{}" "$1"/ \; find "$1" -mindepth 1 -type d -delete +else + log "None found..." fi +log "Searching for audiobook (m4b.mp4) files in completed download..." if [ $(find "$1" -type f -iname "*.m4b.mp4" | wc -l) -gt 0 ]; then log "M4B (m4b.mp4) files found, removing non m4b files..." find "$1" -type f -not -iname "*.m4b.mp4" -delete @@ -47,10 +50,48 @@ if [ $(find "$1" -type f -iname "*.m4b.mp4" | wc -l) -gt 0 ]; then mv "$file" "$1/${fileName%.*}" fi done + log "All files renamed" +else + log "None found..." fi -if [ $(find "$1" -type f -iname "*.m4b" | wc -l) -eq 0 ]; then - echo "ERROR: NO audiobook files found (M4B)" && exit 1 +log "Searching for audiobook (mp3) files in completed download..." +mp3Count=$(find "$1" -type f -iname "*.mp3" | wc -l) +if [ $mp3Count -gt 0 ]; then + log "MP3 files found, removing non mp3 files..." + find "$1" -type f -not -iname "*.mp3" -delete + find "$1" -mindepth 2 -type f -exec mv "{}" "$1"/ \; + find "$1" -mindepth 1 -type d -delete + if [ $mp3Count -gt 1 ]; then + log "ERROR: More than 1 MP3 file found, performing cleanup..." + find "$1" -type f -iname "*.mp3" -delete + fi +else + log "None found..." +fi + +error="false" +bookfound="false" +m4bCount=$(find "$1" -type f -iname "*.m4b" | wc -l) +mp3Count=$(find "$1" -type f -iname "*.m4b" | wc -l) +if [ "$bookfound" == "false" ]; then + if [ $m4bCount -eq 0 ]; then + error="true" + else + bookfound="true" + fi +fi + +if [ "$bookfound" == "false" ]; then + if [ $mp3Count -eq 0 ]; then + error="true" + else + bookfound="true" + fi +fi + +if [ "$error" == "true" ]; then + echo "ERROR: No audiobook files found" && exit 1 fi chmod 777 "$1"