Start on the actual parsing of the music data.

This commit is contained in:
Hyperling 2025-03-19 05:53:15 -07:00
parent 92ac167e0f
commit 20161e48c5

View File

@ -50,11 +50,11 @@ echo "** Tools are available."
# Old Directory #
echo "* Checking whether OLD directory exists."
if [[ "`pwd`"== */OLD ]]; then
if [[ "`pwd`" == *"/OLD" ]]; then
echo "** We are in the folder, moving up a directory."
cd ..
cd ..
fi
if [[ ! -d OLD ]]; then
if [[ ! -d "OLD" ]]; then
echo "ERROR: Could not find a folder named 'OLD'."
echo " Please create it and add your library there."
fi
@ -62,7 +62,7 @@ echo "** Folder exists appropriately."
# Other Directories #
echo "* Ensuring working directories NEW and INTERIM exist."
mkdir -pv $NEW $INT
mkdir -pv "$NEW" "$INT"
## Convert Media ##
@ -70,14 +70,80 @@ echo "* Convert all files to mp3."
find "$OLD" ! -name "*".mp3 | while read file; do
ffmpeg -nostdin -hide_banner -loglevel quiet -i "$file" "$file".converted.mp3
done
echo "** Done creating mp3s."
echo "** Done converting mp3s."
## Transform Media ##
echo "* Moving INTERIM files to NEW."
function migrate_music {
file="$1"
command="$2"
if [[ -z $file ]]; then
echo "ERROR: No filename retrieved, cannot migrate."
return 1
fi
if [[ -z "$command" ]]; then
command="cp"
fi
echo "** $file **"
# Retrieve and clean the Title
title=""
title="`exiftool -Title "$file"`"
title="${title//Title /}"
title="${title// : /}"
title="${title//[^[:alnum:][:space:].]/}"
title="`echo $title`"
while [[ "$title" == *" "* ]]; do
title="${title// / }"
done
echo "*** Title=$title"
new_file="$title$EXT"
# Retrieve and clean the Track#
track=""
# Get raw value
track="`exiftool -Track "$file"`"
# Filter the header
track="${track//Track /}"
track="${track// : /}"
# Remove disk designations
track="${track%%/*}"
# Remove any whitespace before/after
track="`echo $track`"
# Add a leading 0 to single digits.
[[ ${#track} == 1 ]] && track="0$track"
echo "*** Track=$track"
new_file="$track. $new_file"
# Add the Album and Year.
new_file="$parent/$new_file"
# Add the Artist and Genre.
new_file="$grandparent/$new_file"
# Move the file.
new_file="$NEW/$new_file"
$command "$file" "$new_file"
}
echo "* Moving INTERIM files to NEW."
find "$INT" -name "*".mp3 | while read file; do
migrate_music "$file" mv
done
echo "** Done with INTERIM, deleting."
rm -rfv "$INT"
echo "* Copying OLD files to NEW."
find "$OLD" -name "*".mp3 | while read file; do
migrate_music "$file" cp
done