Compare commits

...

3 Commits

Author SHA1 Message Date
yosh e7abdd6793 screenshot: useless vars 2023-12-15 00:06:40 -05:00
yosh 769f0590be can't trap kill 2023-12-15 00:06:26 -05:00
yosh 46b70ef02d albumsetup: simplify, make tracklist sorted 2023-12-15 00:05:56 -05:00
3 changed files with 32 additions and 33 deletions

View File

@ -15,15 +15,15 @@ clean() {
# wrapper to grab a specific tag from flac/opus/mp3
grab_tag() {
case ${1##*.} in
flac) metaflac --show-tag="$2" "$1" | cut -d '=' -f 2- ;;
opus) opusinfo "$1" | awk -v RS='\n' -v FS='=' -v OFS='' "/^\\t$2=/"'{$1=""; print $0}' ;;
flac) metaflac --show-tag="$2" -- "$1" | cut -d '=' -f 2- ;;
opus) opusinfo -- "$1" | awk -v RS='\n' -v FS='=' -v OFS='' "/^\\t$2=/"'{$1=""; print $0}' ;;
mp3)
case "$2" in
ARTIST) id3 -q '%_a' "$1" ;;
ALBUM) id3 -q '%_A' "$1" ;;
TRACKNUMBER) id3 -q '%_###T' "$1" ;;
TITLE) id3 -q '%_t' "$1" ;;
ALBUMARTIST) id3 -2 -q "%|%{TPE2}||%{TXXX:ALBUM ARTIST}|?" "$1" ;;
ARTIST) id3 -q '%_a' -- "$1" ;;
ALBUM) id3 -q '%_A' -- "$1" ;;
TRACKNUMBER) id3 -q '%_###T' -- "$1" ;;
TITLE) id3 -q '%_t' -- "$1" ;;
ALBUMARTIST) id3 -2 -q "%|%{TPE2}||%{TXXX:ALBUM ARTIST}|?" -- "$1" ;;
*) printf 'unknown tag used for mp3' ;;
esac
;;
@ -45,7 +45,7 @@ grab_info() {
}
convert_vid() {
ffmpeg ${VERBOSE--loglevel error} -y -loop 1 -framerate 4 -f image2 -i "$1" -i "$2" \
ffmpeg -nostdin ${VERBOSE--loglevel error} -y -loop 1 -framerate 4 -f image2 -i "$1" -i "$2" \
-t "$DURATION" \
-pix_fmt yuv420p \
${acopy:--c:a libopus -b:a 256k} \
@ -66,7 +66,7 @@ extract_cover() {
case ${1##*.} in
flac) metaflac --export-picture-to="$2" -- "$1" ;;
opus) opustags --output-cover "$2" -- "$1" ;;
mp3) ffmpeg -i "$1" -map "0:v:0" -c:v copy "$2" ;;
mp3) ffmpeg -nostdin -i "$1" -map "0:v:0" -c:v copy "$2" ;;
*) die 'unknown filetype' ;;
esac
} >/dev/null
@ -93,7 +93,7 @@ set_cover() {
trap 'clean' INT HUP QUIT EXIT
SONG="" FULLALBUM="" BANDCAMP="" NO_CONVERT=""
SONG="" BANDCAMP="" NO_CONVERT=""
OUTDIR="/tmp/albumsetup/${PWD##*/}"
while getopts :vnd:e:p:s:b: OPT; do
case "$OPT" in
@ -130,8 +130,15 @@ if [ -n "$SONG" ]; then
# INDIVIDUAL TRACKS FOR FULL ALBUM + COMPLETE VID #
else
total_time=0 # this var helps for more precise timestamps
# make a sorted list of the files by tracknumber first
# so that we don't have to do it individually for everything later
for f in ./*."$EXT"; do
grab_info "$f"
printf '%s\t%s\n' "$TRACKNUMBER" "$f"
done | sort | cut -f 2- > "$OUTDIR/tmp_sorted_list"
total_time=0 # this var helps for more precise timestamps
while read -r f; do
grab_info "$f"
set_cover "$f"
output_file="$OUTDIR/$TRACKNUMBER ${ARTIST%%/*} - ${TITLE%%/*}.webm"
@ -142,35 +149,27 @@ else
rm -f "$COVER_PICTURE"
# metadata print to send to metadata.txt
printf '%s %s - %s - %s\n' "${TRACKNUMBER:-000}" "${ARTIST:-unknown artist}" "${ALBUM:-unknown album}" "${TITLE:-unknown title}"
# STUFF FOR FULL VID #
# metadata for full vid
printf '%02d:%02d:%02d - %s\n' \
"$((${total_time%%.*} / 3600))" "$((${total_time%%.*} % 3600 / 60))" "$((${total_time%%.*} % 60))" \
"$ARTIST - $TITLE" >> "$OUTDIR/metadata_fullvid.txt"
# add to total time, but this is as a float remember that
total_time="$(printf '%s\n' "$total_time + $DURATION" | bc)"
printf '%s - %s - %s\n' "${ARTIST:-unknown artist}" "${ALBUM:-unknown album}" "${TITLE:-unknown title}" \
>> "$OUTDIR/metadata.txt"
# build ffmpeg concat metadata
# make safe filename for ffmpeg concat; replace all ' with '\''
sf="$(printf '%s' "$output_file" | sed "s/'/'\\\\''/g")"
echo "file '$sf'" >> "$OUTDIR/ffmpeg_tracklist.txt"
done > "$OUTDIR/metadata.txt"
# tracklist
printf '%02d:%02d:%02d - %s\n' \
"$((${total_time%%.*} / 3600))" "$((${total_time%%.*} % 3600 / 60))" "$((${total_time%%.*} % 60))" \
"$ARTIST - $TITLE" >> "$OUTDIR/metadata_fullvid.txt"
total_time="$(printf '%s\n' "$total_time + $DURATION" | bc)"
printf "file '%s'\n" "$sf" >> "$OUTDIR/ffmpeg_tracklist.txt"
done < "$OUTDIR/tmp_sorted_list"
[ ! -f "$OUTDIR/metadata.txt" ] && die "No files found!"
# sort by correct track numbers then remove track numbers later
sort -o "$OUTDIR/metadata.txt.sorted" "$OUTDIR/metadata.txt"
sort -o "$OUTDIR/ffmpeg_tracklist.txt" "$OUTDIR/ffmpeg_tracklist.txt"
while read -r track name; do
printf '%s\n' "$name"
done <"$OUTDIR/metadata.txt.sorted" >"$OUTDIR/metadata.txt"
rm "$OUTDIR/metadata.txt.sorted"
if [ -z "$NO_CONVERT" ]; then
errecho "Building full video..."
ffmpeg -safe 0 -f concat -i "$OUTDIR/ffmpeg_tracklist.txt" -c copy "$OUTDIR/$ALBUMARTIST - $ALBUM.webm"
ffmpeg -nostdin -safe 0 -f concat -i "$OUTDIR/ffmpeg_tracklist.txt" -c copy "$OUTDIR/${ALBUMARTIST%%/*} - ${ALBUM%%/*}.webm"
fi
rm "$OUTDIR/ffmpeg_tracklist.txt"

View File

@ -10,7 +10,7 @@ clean() {
[ -f "${tmpfile}" ] && rm -f "$tmpfile"
}
trap 'clean' 1 INT HUP KILL EXIT
trap 'clean' 1 INT HUP QUIT EXIT
for f; do
[ -f "$f" ] || { errecho "File $f is not a regular file, is not accessible by the user, or does not exist. Skipping..." && continue; }

View File

@ -79,7 +79,7 @@ esac
tmpfp="$(mktemp -t screenshot_XXXX.png)"
trap 'clean' EXIT
SCREEN="" REGION="" WINDOW="" FREEZE="" ssopts=""
SCREEN="" REGION="" WINDOW=""
while getopts :srwf OPT; do
case "$OPT" in
s) SCREEN=1 ;; # screen