Recreate repository
This commit is contained in:
47
src/01__metadata.sh
Executable file
47
src/01__metadata.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables for color print.
|
||||
GREEN="\e[32m"
|
||||
RED="\e[31m"
|
||||
CYAN="\e[36m"
|
||||
END="\e[0m"
|
||||
|
||||
# Get command line arguments.
|
||||
while getopts i:o: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
i) input_metadata=${OPTARG};;
|
||||
o) output_dir=${OPTARG};;
|
||||
*) printf "%b\n" "${RED}[ ! ]${END} Invalid Argument"
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
{
|
||||
# Skip header line of .tsv.
|
||||
read -r
|
||||
|
||||
while IFS=$'\t' read -r code extension track title artist album year disc artwork
|
||||
do
|
||||
file_path="${output_dir}/${code}.txt"
|
||||
|
||||
printf "%b: %s\r" "${CYAN}[ i ]${END} Processing file" "${code}${extension}"
|
||||
|
||||
# Create metadata file.
|
||||
touch "${file_path}"
|
||||
|
||||
# Write metadata to file.
|
||||
{
|
||||
printf "%s\t" "${extension}"
|
||||
printf "%s\t" "${track}"
|
||||
printf "%s\t" "${title}"
|
||||
printf "%s\t" "${artist}"
|
||||
printf "%s\t" "${album}"
|
||||
printf "%s\t" "${year}"
|
||||
printf "%s\t" "${disc}"
|
||||
printf "%s" "${artwork}"
|
||||
} >> "${file_path}"
|
||||
|
||||
printf "%b: %s\n" "${GREEN}[ ✓ ]${END} Generated metadata file for" "${code}${extension}"
|
||||
done
|
||||
} < "${input_metadata}"
|
68
src/02__encode.sh
Executable file
68
src/02__encode.sh
Executable file
@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables for color print.
|
||||
GREEN="\e[32m"
|
||||
RED="\e[31m"
|
||||
CYAN="\e[36m"
|
||||
END="\e[0m"
|
||||
|
||||
# Get command line arguments.
|
||||
while getopts i:m:a:o: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
i) input_file=${OPTARG};;
|
||||
m) input_metadata=${OPTARG};;
|
||||
a) artwork_dir=${OPTARG};;
|
||||
o) output_file=${OPTARG};;
|
||||
*) printf "%b\n" "${RED}[ ! ]${END} Invalid Argument"
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf "%b: %s\r" "${CYAN}[ i ]${END} Encoding file" "${input_file}"
|
||||
|
||||
# Read file metadata.
|
||||
IFS=$'\t' read -r extension track title artist album year disc artwork < "${input_metadata}"
|
||||
|
||||
if [[ "${extension}" != ".flac" ]]
|
||||
then
|
||||
ffmpeg \
|
||||
-i "${input_file}" \
|
||||
-vn\
|
||||
-c:a flac \
|
||||
-hide_banner \
|
||||
-loglevel error \
|
||||
"${output_file}"
|
||||
else
|
||||
cp "${input_file}" "${output_file}"
|
||||
fi
|
||||
|
||||
# Remove any exsiting metadata.
|
||||
metaflac \
|
||||
--remove-all-tags \
|
||||
"${output_file}"
|
||||
|
||||
# Remove any album artwork.
|
||||
metaflac \
|
||||
--remove \
|
||||
--block-type=PICTURE,PADDING \
|
||||
--dont-use-padding \
|
||||
"${output_file}"
|
||||
|
||||
metaflac \
|
||||
--remove-tag=COVERART \
|
||||
--dont-use-padding \
|
||||
"${output_file}"
|
||||
|
||||
# Write new metadata.
|
||||
metaflac \
|
||||
--set-tag=ALBUM="${album}" \
|
||||
--set-tag=ARTIST="${artist}" \
|
||||
--set-tag=TITLE="${title}" \
|
||||
--set-tag=TRACKNUMBER="${track}" \
|
||||
--set-tag=DATE="${year}" \
|
||||
--set-tag=DISCNUMBER="${disc}" \
|
||||
--import-picture-from="${artwork_dir}/${artwork}" \
|
||||
"${output_file}"
|
||||
|
||||
printf "%b: %s\n" "${GREEN}[ ✓ ]${END} Succesfully encoded file" "${input_file}"
|
49
src/install.sh
Executable file
49
src/install.sh
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables for color print.
|
||||
GREEN="\e[32m"
|
||||
RED="\e[31m"
|
||||
CYAN="\e[36m"
|
||||
END="\e[0m"
|
||||
|
||||
# Get command line arguments.
|
||||
while getopts r:m:i: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
r) encode_dir=${OPTARG};;
|
||||
m) metadata_dir=${OPTARG};;
|
||||
i) install_dir=${OPTARG};;
|
||||
*) printf "%b\n" "${RED}[ ! ]${END} Invalid Argument"
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Create install directory (if it does not exist).
|
||||
mkdir -p "${install_dir}"
|
||||
|
||||
for file in "${metadata_dir}"/*.txt
|
||||
do
|
||||
# Read file metadata.
|
||||
IFS=$'\t' read -r extension track title artist album year disc artwork < "${file}"
|
||||
|
||||
# Get filename without extension.
|
||||
filename=$(basename "${file}" ".txt")
|
||||
|
||||
# Replace any '/' with '-' in the song title.
|
||||
title="${title//\//-}"
|
||||
|
||||
# Add leading zeroes to disc number.
|
||||
disc_num=$(printf "%02d" "${disc}")
|
||||
|
||||
# Add leading zeroes to track number.
|
||||
track_num=$(printf "%02d" "${track}")
|
||||
|
||||
# Create album directory (if it does not exist).
|
||||
mkdir -p "${install_dir}/${album}"
|
||||
|
||||
# Copy file to installation directory and rename.
|
||||
cp "${encode_dir}/${filename}.flac" \
|
||||
"${install_dir}/${album}/${disc_num}-${track_num} - ${title}.flac"
|
||||
|
||||
printf "%b: %s\n" "${GREEN}[ ✓ ]${END} Succesfully installed file" "${filename}"
|
||||
done
|
Reference in New Issue
Block a user