Fix removal of OLD if the file was converted. More changes to output.

This commit is contained in:
Hyperling 2025-04-13 11:37:25 -07:00
parent 7959609a33
commit 6c4d752e92

View File

@ -249,18 +249,18 @@ function migrate_music {
new_file="$NEW_DIR/$new_file" new_file="$NEW_DIR/$new_file"
$command -v "$file" "$new_file" $command -v "$file" "$new_file"
echo -e "*** Finished file!\n" echo "*** Finished file!"
} }
## Main ## ## Main ##
# Convert Media # # Convert Media #
echo "* Ensure all files are mp3." echo -e "\n* Ensure all files are mp3."
find "$OLD_DIR" -type f ! -name "*".$EXT | sort | while read file; do find "$OLD_DIR" -type f ! -name "*".$EXT | sort | while read non_mp3; do
echo "** Working on '$file'." echo "** Working on '$non_mp3'."
temp_file="`basename "$file"`" temp_file="`basename "$non_mp3"`"
temp_file="$INT_DIR/${temp_file//[^[:alnum:][:space:].]/}.$EXT" temp_file="$INT_DIR/${temp_file//[^[:alnum:][:space:].]/}.$EXT"
echo "temp_file='$temp_file'" echo "temp_file='$temp_file'"
@ -269,14 +269,14 @@ find "$OLD_DIR" -type f ! -name "*".$EXT | sort | while read file; do
# Actual conversion. # Actual conversion.
ffmpeg -y \ ffmpeg -y \
-nostdin -hide_banner -loglevel quiet \ -nostdin -hide_banner -loglevel quiet \
-i "$file" "$temp_file" -i "$non_mp3" "$temp_file"
status="$?" status="$?"
fi fi
if [[ $status != 0 ]]; then if [[ $status != 0 ]]; then
echo "*** FAILED: Exited with status '$status'." echo "*** FAILED: Exited with status '$status'."
echo "**** To troubleshoot, try running this:" echo "**** To troubleshoot, try running this:"
echo "ffmpeg -y -i \"$file\" \"$temp_file\"" echo "ffmpeg -y -i \"$non_mp3\" \"$temp_file\""
exit exit
fi fi
echo "*** Success!" echo "*** Success!"
@ -284,12 +284,16 @@ find "$OLD_DIR" -type f ! -name "*".$EXT | sort | while read file; do
echo "*** Moving file to NEW." echo "*** Moving file to NEW."
migrate_music "$temp_file" $cmd migrate_music "$temp_file" $cmd
echo "*** Removing original." echo "** Removing original."
echo "$temp_file"
echo "$non_mp3"
if [[ -d ~/TRASH ]]; then if [[ -d ~/TRASH ]]; then
mv -v "$file" ~/TRASH/ mv -v "$non_mp3" ~/TRASH/
else else
rm -v "$file" rm -v "$non_mp3"
fi fi
echo -e "\n"
done done
echo "** Done converting any mp3s." echo "** Done converting any mp3s."
@ -299,4 +303,5 @@ rm -rfv "$INT_DIR"
echo "* Copying OLD files to NEW." echo "* Copying OLD files to NEW."
find "$OLD_DIR" -name "*".$EXT | sort | while read file; do find "$OLD_DIR" -name "*".$EXT | sort | while read file; do
migrate_music "$file" $cmd migrate_music "$file" $cmd
echo -e "\n"
done done