Imported functions from git2git
This commit is contained in:
parent
908995efa7
commit
a7eb032bc2
10 changed files with 335 additions and 0 deletions
22
src/cmd_import_tracks
Normal file
22
src/cmd_import_tracks
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc cmd_import_tracks {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# cmd_import_tracks - Wrapper for import_tracks
|
||||
#
|
||||
# USAGE
|
||||
# cmd_import_tracks </path/to/work/dir> <subpath/to/album>
|
||||
#
|
||||
# }
|
||||
|
||||
cmd_import_tracks {
|
||||
local ROOT="${1}"; shift 1
|
||||
local dirList=("${@}")
|
||||
for dir in ${dirList[@]}; do
|
||||
folderList=($(find ${ROOT}/${dir} -name '*cover*' -printf '%h\n' | awk '!seen[$0]++' | sed "s|${ROOT}/||g"))
|
||||
for folder in ${folderList[@]}; do
|
||||
gen ${ROOT} "${folder}"
|
||||
done
|
||||
done
|
||||
}
|
48
src/gen_cue
Normal file
48
src/gen_cue
Normal file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc gen_cue {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# gen_cue - Generates cue file from print_meta function
|
||||
#
|
||||
# USAGE
|
||||
# gen_cue <output from file_name> <output from print_meta_tracks> <file_1> [<file_2>] [<...>]
|
||||
#
|
||||
# }
|
||||
|
||||
gen_cue() {
|
||||
local FILE_NAME="${1}"
|
||||
local METADATA="${2}"; shift 2
|
||||
local fileList=("${@}")
|
||||
|
||||
# Metadata Parsing
|
||||
metadataList=($(echo ${METADATA} | sed 's|;| |g'))
|
||||
for metadata in ${metadataList[@]}; do
|
||||
eval local ${metadata}
|
||||
done
|
||||
|
||||
for file in ${fileList[@]}; do
|
||||
local trackList=(${trackList[@]} $(echo ${file} | sed 's|.*/||' | awk 'BEGIN{ FS="-"; OFS=":"}{$1=""}{print $0}' | sed 's|: ||'))
|
||||
done
|
||||
|
||||
# Generates breaklist
|
||||
breakList=($(gen_breaklist ${fileList[@]}))
|
||||
|
||||
[[ ! -z "${META_DATE+x}" ]] && echo "REM DATE ${META_DATE}"
|
||||
[[ ! -z "${META_COMPOSER+x}" ]] && echo "PERFORMER \"${META_COMPOSER}\""
|
||||
[[ ! -z "${META_CONDUCTOR+x}" ]] && echo "REM CONDUCTOR \"${META_CONDUCTOR}\""
|
||||
[[ ! -z "${META_ORCHESTRA+x}" ]] && echo "REM ORCHESTRA \"${META_ORCHESTRA}\""
|
||||
[[ ! -z "${META_ARTIST+x}" ]] && echo "PERFORMER \"${META_ARTIST}\""
|
||||
[[ ! -z "${META_ALBUM+x}" ]] && echo "TITLE \"${META_ALBUM}\""
|
||||
echo "FILE \"${FILE_NAME}.flac\" WAVE"
|
||||
local COUNT=0
|
||||
while [[ ${COUNT} -lt ${#breakList[@]} ]]; do
|
||||
[[ ${COUNT} -le 8 ]] && local TRACK_NO="0$(( ${COUNT} + 1 ))" || local TRACK_NO="$(( ${COUNT} + 1 ))"
|
||||
echo " TRACK ${TRACK_NO} AUDIO"
|
||||
echo " TITLE \"${trackList[${COUNT}]}\""
|
||||
echo " INDEX 01 ${breakList[${COUNT}]}"
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
32
src/gen_image
Normal file
32
src/gen_image
Normal file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc gen_image {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# gen_image - Generates image from list of lossless audio files
|
||||
#
|
||||
# USAGE
|
||||
# gen_image <file_1> [<file_1>] [<...>]
|
||||
#
|
||||
# }
|
||||
|
||||
gen_image() {
|
||||
local fileList=("${@}")
|
||||
if [[ ${#fileList[@]} -eq 1 ]]; then
|
||||
cat ${fileList[@]} > joined.flac
|
||||
else
|
||||
shntool join -O always ${fileList[@]} -o flac
|
||||
if [[ $? -ne 0 ]]; then
|
||||
med_convert wav ${fileList[@]}
|
||||
[[ $? -ne 0 ]] && { echo "Image generation failed with fatal errors"; return 1; }
|
||||
echo ${fileList[@]}
|
||||
fileList=($(printf '%s\n' ${fileList[@]} | sed 's|flac|wav|'))
|
||||
echo ${fileList[@]}
|
||||
shntool join -O always ${fileList[@]} -o flac
|
||||
[[ $? -ne 0 ]] && { echo "Image generation failed with fatal errors"; return 1; }
|
||||
echo "Image generated with non-fatal error"; return 2
|
||||
fi
|
||||
fi
|
||||
echo "Image generated with no errors"; return 0
|
||||
}
|
||||
|
73
src/import_tracks
Normal file
73
src/import_tracks
Normal file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc import_tracks
|
||||
#
|
||||
# DESCRIPTION
|
||||
# import_tracks - Import tracks into git directory
|
||||
#
|
||||
# USAGE
|
||||
# import_tracks "</path/to/work/dir> <subpath/to/album>
|
||||
#
|
||||
# }
|
||||
|
||||
import_tracks() {
|
||||
local ROOT="${1}"
|
||||
local SUBFOL="${2}"
|
||||
local FOLDER="${ROOT}/${SUBFOL}"
|
||||
local CDCOUNT="$(cdcount "${FOLDER}")"
|
||||
local COUNT=1
|
||||
local SOURCE=FLAC
|
||||
|
||||
while [[ ${COUNT} -le ${CDCOUNT} ]]; do
|
||||
|
||||
# Generates file list depending on CD count
|
||||
if [[ "${CDCOUNT}" == 1 ]]; then
|
||||
local fileList=($(find "${FOLDER}"/* \( -name '*.flac' -or -name '*.mp3' -or -name '*.wav' \) -printf '%p\t'))
|
||||
else
|
||||
local fileList=($(find "${FOLDER}"/${COUNT}.* \( -name '*.flac' -or -name '*.mp3' \) -printf '%p\t'))
|
||||
fi
|
||||
|
||||
if ismp3 ${fileList[@]}; then
|
||||
_msg EXEC "Converting MP3 files to FLAC"
|
||||
med_convert flac ${fileList[@]} >${STDERR} 2>&1
|
||||
[[ $? -eq 0 ]] && _msg OK || _msg WARN
|
||||
local SOURCE=MP3
|
||||
fi
|
||||
[[ "${SOURCE}" == "MP3" ]] && local fileList=($(printf "%s\t" ${fileList[@]} | sed 's|mp3|flac|g'))
|
||||
|
||||
# Generates image
|
||||
_msg EXEC "Generating data for ${FOLDER} disk ${COUNT} of ${CDCOUNT}"
|
||||
gen_image ${fileList[@]} >${STDERR} 2>&1
|
||||
local EXIT="$?"
|
||||
if [[ ${EXIT} -eq 0 ]]; then
|
||||
_msg OK
|
||||
elif [[ ${EXIT} -eq 2 ]]; then
|
||||
_msg WARN
|
||||
else
|
||||
_msg FAIL
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Determines file name based on image's CHKSUM and acts accordingly
|
||||
metaflac --remove-all --dont-use-padding joined.flac
|
||||
local SHA256=$(sha256sum joined.flac | cut -d' ' -f1)
|
||||
local FILE_NAME=$(file_name ${SOURCE} ${SHA256})
|
||||
mv joined.flac ${FILE_NAME}.flac
|
||||
|
||||
# Generates METADATA, CUE and MTAG
|
||||
_msg EXEC "Generating metadata for ${FOLDER} disk ${COUNT} of ${CDCOUNT}"
|
||||
local METADATA="$(gen_metadata "${SUBFOL}" ${COUNT} ${CDCOUNT})"
|
||||
gen_cue "${FILE_NAME}" ${METADATA} ${fileList[@]} > ${FILE_NAME}.cue
|
||||
[[ $? -ne 0 ]] && _msg WARN
|
||||
addbom ${FILE_NAME}.cue
|
||||
gen_mtag "${FILE_NAME}" ${METADATA} ${fileList[@]} > ${FILE_NAME}.tags
|
||||
[[ $? -ne 0 ]] && _msg WARN
|
||||
addbom ${FILE_NAME}.tags
|
||||
gen_cover "${FOLDER}" > ${FILE_NAME}.jpg
|
||||
[[ $? -ne 0 ]] && _msg WARN || _msg OK
|
||||
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
|
||||
}
|
21
src/ismp3
Normal file
21
src/ismp3
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc ismp3 {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# ismp3 - Returns true if any file present is an mp3
|
||||
#
|
||||
# USAGE
|
||||
# ismp3 <files>
|
||||
#
|
||||
# }
|
||||
|
||||
ismp3() {
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
local FILE_EXT="$(echo "${file}" | sed 's|.*\.||')"
|
||||
[[ "${FILE_EXT}" == "mp3" ]] && local MP3=0 || local MP3=1
|
||||
done
|
||||
[[ ${MP3} -eq 0 ]] && return 0 || return 1
|
||||
}
|
||||
|
22
src/med_convert
Normal file
22
src/med_convert
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc med_convert {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# med_convert - Convers files from one format to another
|
||||
#
|
||||
# USAGE
|
||||
# med_convert <output format> <file_1> [<...>]
|
||||
#
|
||||
# }
|
||||
|
||||
med_convert() {
|
||||
local EXT="${1}"; shift 1
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
local FILE_EXT="$(echo "${file}" | sed 's|.*\.||')"
|
||||
ffmpeg -loglevel 24 -y -i "${file}" "$(echo ${file} | sed "s|${FILE_EXT}|${EXT}|")" >${STDERR} 2>&1
|
||||
[[ $? -ne 0 ]] && local ERROR=true
|
||||
done
|
||||
[[ ${ERROR} ]] && return 1 || return 0
|
||||
}
|
33
src/print_cue_breaklist
Normal file
33
src/print_cue_breaklist
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc print_cue_breaklist {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# print_cue_breaklist - Prints breaklist from files
|
||||
#
|
||||
# USAGE
|
||||
# print_cue_breaklist <file_1> [<...>]
|
||||
#
|
||||
# }
|
||||
|
||||
print_cue_breaklist() {
|
||||
local fileList=("${@}")
|
||||
local breakList=(0:00:00)
|
||||
if shntool cue ${fileList[@]} >/dev/null 2>&1; then
|
||||
shntool cue ${fileList[@]} > joined.cue
|
||||
local breakList=(${breakList[@]} $(cuebreakpoints joined.cue | sed 's|\.|:|g'))
|
||||
rm joined.cue
|
||||
else
|
||||
local durList=($(soxi -D "${fileList[@]}"))
|
||||
local breaksecList=(0)
|
||||
local COUNT=0
|
||||
while [[ $(( ${COUNT} + 1 )) -lt ${#durList[@]} ]]; do
|
||||
local breaksecList=(${breaksecList[@]} $(awk "BEGIN {printf ${breaksecList[-1]} + ${durList[${COUNT}]}}" ))
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
local breaksecList=($(printf "%s\n" ${breaksecList[@]} | sed 's|\..*||g'))
|
||||
local breakList=($(sec2min ${breaksecList[@]}))
|
||||
fi
|
||||
printf '%s\n' ${breakList[@]}
|
||||
}
|
||||
|
36
src/print_meta_tracks
Normal file
36
src/print_meta_tracks
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc print_meta_tracks
|
||||
#
|
||||
# DESCRIPTION
|
||||
# print_meta_tracks - Parses track files and prints out metadata
|
||||
#
|
||||
# USAGE
|
||||
# print_meta_tracks </path/to/album> <disc_no> <Number of total discs>
|
||||
#
|
||||
# }
|
||||
|
||||
gen_metadata() {
|
||||
local FOLDER="${1}"
|
||||
local DISC_NO="${2}"
|
||||
local META_DISCTOT="${3}"
|
||||
local META_GENRE=$(echo ${FOLDER} | cut -d/ -f1)
|
||||
echo -n "META_GENRE=\"${META_GENRE}\";"
|
||||
echo -n "META_DISCTOT=${META_DISCTOT};"
|
||||
echo -n "META_DISCNUM=${DISC_NO};"
|
||||
if [[ "${META_GENRE}" == "Classical" ]] && [[ "$(echo ${FOLDER} | cut -d/ -f5 | cut -d- -f2 | sed 's| ||')" != "" ]]; then
|
||||
echo -n "META_COMPOSER=\"$(echo ${FOLDER} | cut -d/ -f2)\";"
|
||||
echo -n "META_ALBUM=\"$(echo ${FOLDER} | cut -d/ -f3)\";"
|
||||
echo -n "META_CONDUCTR=\"$(echo ${FOLDER} | cut -d/ -f4)\";"
|
||||
echo -n "META_DATE=\"$(echo ${FOLDER} | cut -d/ -f5 | cut -d- -f1 | rev | sed 's| ||' | rev)\";"
|
||||
echo -n "META_ORCHESTRA=\"$(echo ${FOLDER} | cut -d/ -f5 | cut -d- -f2 | sed 's| ||')\";"
|
||||
elif [[ "${META_GENRE}" == "Soundtrack" ]]; then
|
||||
echo -n "META_ALBUM=\"$(echo ${FOLDER} | cut -d/ -f2)\""
|
||||
else
|
||||
echo -n "META_ARTIST=\"$(echo ${FOLDER} | cut -d/ -f2)\";"
|
||||
echo -n "META_DATE=\"$(echo ${FOLDER} | cut -d/ -f3 | cut -d- -f1 | rev | sed 's| ||' | rev)\";"
|
||||
echo -n "META_ALBUM=\"$(echo ${FOLDER} | cut -d/ -f3 | sed 's|.*\ -\ ||')\";"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
22
src/print_sec_to_min
Normal file
22
src/print_sec_to_min
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc print_sec_to_min
|
||||
#
|
||||
# DESCRIPTION
|
||||
# print_sec_to_min - Prints minutes out of seconds in min:sec:micro format usable
|
||||
# by cuetools
|
||||
#
|
||||
# USAGE
|
||||
# print_sec_to_min <value> [<...>]
|
||||
#
|
||||
|
||||
print_sec_to_min() {
|
||||
local secList=("${@}")
|
||||
for sec in ${secList[@]}; do
|
||||
MIN=$(($sec%3600/60))
|
||||
SEC=$(($sec%60))
|
||||
[[ ${sec} -ge 3600 ]] && MIN=$(( ${MIN} + 60 ))
|
||||
printf '%02d:%02d:%02d\n' ${MIN} ${SEC} 00
|
||||
done
|
||||
}
|
||||
|
26
src/print_tracks_cdcount
Normal file
26
src/print_tracks_cdcount
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc print_tracks_cdcount {
|
||||
#
|
||||
# DESCRIPTIONS
|
||||
# print_tracks_cdcount - Prints number of CDs
|
||||
#
|
||||
# USAGE
|
||||
# print_tracks_cdcount </path/to/album>
|
||||
#
|
||||
# }
|
||||
|
||||
print_tracks_cdcount() {
|
||||
local FOLDER="${1}"
|
||||
local tracknoList=($(find "${1}"/* -type f -follow -not -name '*cover*' -not -name '*.pdf' -printf '%f\n' | cut -d' ' -f1))
|
||||
|
||||
for trackno in ${tracknoList[@]}; do
|
||||
if [[ ${trackno} == *.* ]]; then
|
||||
local CDCOUNT=$(echo ${trackno} | cut -d. -f1)
|
||||
else
|
||||
local CDCOUNT=1
|
||||
fi
|
||||
done
|
||||
echo ${CDCOUNT}
|
||||
}
|
||||
|
Loading…
Reference in a new issue