Refactor program so that each converted file is instantly moved to the NEW directory struture. Start using mv
for all operations and remove the non-MP3 originals after converted successfully.
This commit is contained in:
parent
a513995ad9
commit
38aceb3220
@ -32,6 +32,8 @@ OLD_DIR="$DIR/$OLD"
|
|||||||
NEW_DIR="$DIR/$NEW"
|
NEW_DIR="$DIR/$NEW"
|
||||||
INT_DIR="$DIR/$INT"
|
INT_DIR="$DIR/$INT"
|
||||||
|
|
||||||
|
cmd="mv"
|
||||||
|
|
||||||
## Checks and Setup ##
|
## Checks and Setup ##
|
||||||
|
|
||||||
# System Packages #
|
# System Packages #
|
||||||
@ -70,43 +72,9 @@ echo "** Folder exists appropriately."
|
|||||||
echo "* Ensuring working directories NEW and INTERIM exist."
|
echo "* Ensuring working directories NEW and INTERIM exist."
|
||||||
mkdir -pv "$NEW_DIR" "$INT_DIR"
|
mkdir -pv "$NEW_DIR" "$INT_DIR"
|
||||||
|
|
||||||
## Convert Media ##
|
## Functions ##
|
||||||
|
|
||||||
# TODO: Use the INTERIM folder folder, or remove references to it entirely.
|
# Transform Media #
|
||||||
echo "* Ensure all files are mp3."
|
|
||||||
find "$OLD_DIR" -type f ! -name "*".$EXT | sort | while read file; do
|
|
||||||
echo "** Working on '$file'."
|
|
||||||
|
|
||||||
TEMP_DIR="`dirname "$file"`"
|
|
||||||
TEMP_DIR="${TEMP_DIR//$OLD/$INT}"
|
|
||||||
echo "TEMP_DIR='$TEMP_DIR'"
|
|
||||||
mkdir -pv "$TEMP_DIR"
|
|
||||||
|
|
||||||
TEMP_FILE="`basename "$file"`"
|
|
||||||
TEMP_FILE="${TEMP_FILE//[^[:alnum:][:space:].]/}"
|
|
||||||
echo "TEMP_FILE='$TEMP_FILE'"
|
|
||||||
|
|
||||||
if [[ -s "$TEMP_DIR/$TEMP_FILE" ]]; then
|
|
||||||
echo "*** Skipping file, already exists!"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Actual conversion.
|
|
||||||
ffmpeg -y \
|
|
||||||
-nostdin -hide_banner -loglevel quiet \
|
|
||||||
-i "$file" "${file//$OLD/$INT}".$EXT
|
|
||||||
status="$?"
|
|
||||||
if [[ $status != 0 ]]; then
|
|
||||||
echo "*** FAILED: Exited with status '$status'."
|
|
||||||
echo "**** To troubleshoot, try running this:"
|
|
||||||
echo "ffmpeg -y -i \"$file\" \"${file//$OLD/$INT}\".$EXT"
|
|
||||||
else
|
|
||||||
echo "*** Success!"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo "** Done converting any mp3s."
|
|
||||||
|
|
||||||
## Transform Media ##
|
|
||||||
|
|
||||||
function migrate_music {
|
function migrate_music {
|
||||||
file="$1"
|
file="$1"
|
||||||
@ -270,7 +238,7 @@ function migrate_music {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$skip" == "true" ]]; then
|
if [[ "$skip" == "true" ]]; then
|
||||||
echo "*** Skipping file, critical data missing."
|
echo -e "*** Skipping, critical data missing, please add EXIF data.\n"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -281,18 +249,54 @@ 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 "*** Finished file!"
|
echo -e "*** Finished file!\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "* Moving INTERIM files to NEW."
|
## Main ##
|
||||||
find "$INT_DIR" -name "*".$EXT | sort | while read file; do
|
|
||||||
migrate_music "$file" mv
|
# Convert Media #
|
||||||
|
|
||||||
|
echo "* Ensure all files are mp3."
|
||||||
|
find "$OLD_DIR" -type f ! -name "*".$EXT | sort | while read file; do
|
||||||
|
echo "** Working on '$file'."
|
||||||
|
|
||||||
|
temp_file="`basename "$file"`"
|
||||||
|
temp_file="$INT_DIR/${temp_file//[^[:alnum:][:space:].]/}.$EXT"
|
||||||
|
echo "temp_file='$temp_file'"
|
||||||
|
|
||||||
|
status=""
|
||||||
|
if [[ ! -s "$temp_file" ]]; then
|
||||||
|
# Actual conversion.
|
||||||
|
ffmpeg -y \
|
||||||
|
-nostdin -hide_banner -loglevel quiet \
|
||||||
|
-i "$file" "$temp_file"
|
||||||
|
status="$?"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $status != 0 ]]; then
|
||||||
|
echo "*** FAILED: Exited with status '$status'."
|
||||||
|
echo "**** To troubleshoot, try running this:"
|
||||||
|
echo "ffmpeg -y -i \"$file\" \"$temp_file\""
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
echo "*** Success!"
|
||||||
|
|
||||||
|
echo "*** Moving file to NEW."
|
||||||
|
migrate_music "$temp_file" $cmd
|
||||||
|
|
||||||
|
echo "*** Removing original."
|
||||||
|
if [[ -d ~/TRASH ]]; then
|
||||||
|
mv -v $file ~/TRASH/
|
||||||
|
else
|
||||||
|
rm -v $file
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
echo "** Done converting any mp3s."
|
||||||
|
|
||||||
echo "** Done with INTERIM, deleting."
|
echo "** Done with INTERIM, deleting."
|
||||||
rm -rfv "$INT_DIR"
|
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" cp
|
migrate_music "$file" $cmd
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user