v1.6 - Allow only 1 M4b and 1 MP3 file
This commit is contained in:
parent
1996dfae10
commit
1d9bbcd5f3
1 changed files with 51 additions and 40 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/with-contenv bash
|
||||
ScriptVersion="1.5"
|
||||
ScriptVersion="1.6"
|
||||
scriptName="Audiobook"
|
||||
|
||||
#### Import Settings
|
||||
|
@ -15,7 +15,7 @@ if [ -z $allowM4b ]; then
|
|||
fi
|
||||
|
||||
if [ -z $allowMp3 ]; then
|
||||
allowMp3=false
|
||||
allowMp3=true
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
@ -29,54 +29,65 @@ SECONDS=0
|
|||
log "Processing $1"
|
||||
log "Searching for audiobook (m4b) files in completed download..."
|
||||
m4bCount=$(find "$1" -type f -iname "*.m4b" | wc -l)
|
||||
if [ $m4bCount -gt 0 ]; then
|
||||
log "$m4bCount 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
|
||||
if [ $m4bCount -ne 1 ]; then
|
||||
log "ERROR: More than 1 M4B file found, performing cleanup..."
|
||||
find "$1" -type f -iname "m4b" -delete
|
||||
else
|
||||
log "None found..."
|
||||
fi
|
||||
if [ $m4bCount -gt 0 ]; then
|
||||
log "$m4bCount 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
|
||||
fi
|
||||
|
||||
log "Searching for audiobook (m4b.mp4) files in completed download..."
|
||||
mp4Count=$(find "$1" -type f -iname "*.m4b.mp4" | wc -l)
|
||||
if [ $mp4Count -gt 0 ]; then
|
||||
log "$mp4Count M4B (m4b.mp4) files found, removing non m4b files..."
|
||||
find "$1" -type f -not -iname "*.m4b.mp4" -delete
|
||||
find "$1" -mindepth 2 -type f -exec mv "{}" "$1"/ \;
|
||||
find "$1" -mindepth 1 -type d -delete
|
||||
log "Renaming m4b.mp4 files to m4b..."
|
||||
count=0
|
||||
fileCount=$(find "$1" -type f -iname "*.m4b.mp4"| wc -l)
|
||||
find "$1" -type f -iname "*.m4b.mp4" -print0 | while IFS= read -r -d '' file; do
|
||||
count=$(($count+1))
|
||||
baseFileName="${file%.*}"
|
||||
fileName="$(basename "$file")"
|
||||
extension="${fileName##*.}"
|
||||
log "$count of $fileCount :: Processing $fileName"
|
||||
if [ -f "$file" ]; then
|
||||
mv "$file" "$1/${fileName%.*}"
|
||||
fi
|
||||
done
|
||||
log "All files renamed"
|
||||
if [ $mp4Count -ne 1 ]; then
|
||||
log "ERROR: More than 1 MP4 file found, performing cleanup..."
|
||||
find "$1" -type f -iname "*.mp4" -delete
|
||||
else
|
||||
log "None found..."
|
||||
if [ $mp4Count -gt 0 ]; then
|
||||
log "$mp4Count M4B (m4b.mp4) files found, removing non m4b files..."
|
||||
find "$1" -type f -not -iname "*.m4b.mp4" -delete
|
||||
find "$1" -mindepth 2 -type f -exec mv "{}" "$1"/ \;
|
||||
find "$1" -mindepth 1 -type d -delete
|
||||
log "Renaming m4b.mp4 files to m4b..."
|
||||
count=0
|
||||
fileCount=$(find "$1" -type f -iname "*.m4b.mp4"| wc -l)
|
||||
find "$1" -type f -iname "*.m4b.mp4" -print0 | while IFS= read -r -d '' file; do
|
||||
count=$(($count+1))
|
||||
baseFileName="${file%.*}"
|
||||
fileName="$(basename "$file")"
|
||||
extension="${fileName##*.}"
|
||||
log "$count of $fileCount :: Processing $fileName"
|
||||
if [ -f "$file" ]; then
|
||||
mv "$file" "$1/${fileName%.*}"
|
||||
fi
|
||||
done
|
||||
log "All files renamed"
|
||||
else
|
||||
log "None found..."
|
||||
fi
|
||||
fi
|
||||
|
||||
log "Searching for audiobook (mp3) files in completed download..."
|
||||
mp3Count=$(find "$1" -type f -iname "*.mp3" | wc -l)
|
||||
if [ $mp3Count -gt 0 ]; then
|
||||
log "$mp3Count 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 -ne 1 ]; then
|
||||
log "ERROR: More than 1 MP3 file found, performing cleanup..."
|
||||
find "$1" -type f -iname "*.mp3" -delete
|
||||
fi
|
||||
if [ $mp3Count -ne 1 ]; then
|
||||
log "ERROR: More than 1 MP3 file found, performing cleanup..."
|
||||
find "$1" -type f -iname "*.mp3" -delete
|
||||
else
|
||||
log "None found..."
|
||||
fi
|
||||
if [ $mp3Count -gt 0 ]; then
|
||||
log "$mp3Count 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
|
||||
else
|
||||
log "None found..."
|
||||
fi
|
||||
fi
|
||||
|
||||
error="false"
|
||||
bookfound="false"
|
||||
|
|
Loading…
Reference in a new issue