diff --git a/.README.md b/.README.md index 0d32141..0250a7e 100644 --- a/.README.md +++ b/.README.md @@ -483,7 +483,7 @@ Command|Description ---|--- `ffmpeg_mux_audio `|Mux external audio into one container with video (replaces original audio). Run inside dir with original video. names should be the same for each video. `ffmpeg_mux_cover `|Mux image into files of specified format. -`ffmpeg_music_artist `|Change audio artist metadata. +`ffmpeg_music_meta `|Detect and update music metadata. ## File. diff --git a/.config/bash/module/ffmpeg.sh b/.config/bash/module/ffmpeg.sh index 6354098..f29e426 100644 --- a/.config/bash/module/ffmpeg.sh +++ b/.config/bash/module/ffmpeg.sh @@ -4,7 +4,7 @@ ffmpeg_mux_audio() { if [[ "$1" = "" ]]; then echo "usage: ffmpeg_mux_audio " - return + return 2 fi for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done @@ -16,7 +16,7 @@ ffmpeg_mux_cover() { if [[ "${1}" = "" ]]; then echo "Usage: ffmpeg_mux_cover " - return + return 2 fi local format="${1}" @@ -28,28 +28,36 @@ ffmpeg_mux_cover() ffmpeg -i "${file}" -i "${cover}" -map 0:a -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"${file}" || return 1 done - mv out/* . && rm -d out/ && rm "${2}" + mv out/* . + rm -d out/ && rm "${2}" } -# Change audio artist metadata. -# Usage: ffmpeg_music_artist -ffmpeg_music_artist() +# Change music metadata. +# Usage: ffmpeg_music_meta +ffmpeg_music_meta() { if [[ "${1}" = "" ]]; then - echo "Usage: ffmpeg_music_artist " - return + echo "Usage: ffmpeg_mux_cover " + return 2 fi local format="${1}" - local artist="${2}" + + local artist="${PWD%/*}"; artist="${artist##*/}" + local album="${PWD##*/}"; album="${album#*_}" + local year="${PWD##*/}"; year="${year%%_*}" mkdir out for file in *.${format}; do - ffmpeg -i "${file}" -c copy -metadata "ARTIST=${artist}" -metadata "album_artist=${artist}" ./out/"${file}" || return 1 + local track="${file%%_*}" + local title="${file#*_}"; title="${title%.*}" + + ffmpeg -i "${file}" -c copy -metadata "artist=${artist}" -metadata "album_artist=${artist}" -metadata "album=${album}" -metadata "date=${year}" -metadata "track=${track}" -metadata "title=${title}" ./out/"${file}" || return 1 done - mv out/* . && rm -d out/ + mv out/* . + rm -d out/ } _ffprobe_fps()