Ffmpeg: Add checks for ffmpeg_music_meta.

This commit is contained in:
Dmitry Voronin 2025-02-05 19:44:21 +03:00
parent c65a5ae8c6
commit ecefedf7cd
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k

View file

@ -65,16 +65,38 @@ function ffmpeg_music_meta() {
year="${year%%_*}"
# local total=$(ls *.${format} | wc -l)
# Check.
if [[ ${album} == "" ]]; then
_error "Failed to get the album name!"
return 1
fi
if [[ ${artist} == "" ]]; then
_error "Failed to get the artist name!"
return 1
fi
if [[ ${year} == "" ]]; then
_error "Failed to get the year!"
return 1
fi
mkdir out
for file in *.${format}; do
local track="${file%%_*}"
track=$((10#${track}))
[[ ${track} == "" ]] && track=0
local title="${file#*_}"
title="${title%.*}"
title="${title//_/ }"
if [[ ${track} == "" ]]; then
_error "Failed to get the track number!"
return 1
fi
if [[ ${title} == "" ]]; then
_error "Failed to get the title name!"
return 1
fi
# echo "${artist}; ${album}; ${year}; ${track}; ${title}"
# TODO: make it format-specific.
ffmpeg -i "${file}" -map 0 -c copy -metadata "artists=" -metadata "artist=${artist}" -metadata "album_artist=${artist}" -metadata "album=${album}" -metadata "date=${year}" -metadata "year=${year}" -metadata "date_released=${year}" -metadata "track=${track}" -metadata "part_number=${track}" -metadata "title=${title}" ./out/"${file}" || return 1