lav-outils/podcasts/scripts/make-metadata-image-podcast.sh

51 lines
1.9 KiB
Bash
Raw Normal View History

2019-01-16 12:21:51 +01:00
#!/bin/bash
usage() { echo "$0 -s source_file -d destination_file -u http://... -t \"title\" -p path/to/ffmpeg/binary"; exit 0; }
[ $# -eq 0 ] && usage
while getopts "s:d:u:t:p:h" arg; do
case $arg in
s)
source=${OPTARG}
;;
d)
destination=${OPTARG}
;;
u)
url=${OPTARG}
;;
t)
title=${OPTARG}
;;
p)
FFmpegBin=${OPTARG}
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
if [ ! -f $source ]; then
echo "File $source does not exist"
usage
exit 1
fi
if [ ! -f "$FFmpegBin" ]; then
echo "$FFmpegBin is not executable"
usage
exit 1
fi
image="lav-outils/podcasts/images/image-pour-etiqueter-podcast.jpg"
2019-01-16 12:21:51 +01:00
fichiertemp="$(command mktemp -t "tmp.XXXXXXXXXX.ogg")"
(echo -en ";FFMETADATA1\nMETADATA_BLOCK_PICTURE=";(i=${image};t=3;m="image/jpeg";eval "w=`identify-im6 "$i"|awk '{g=$3;sub("x"," h=",g);print g;d=$5;gsub(/-.*/,"",d);print " d=" d}'`"; echo -en "\x00\x00\x00\x$(printf '%02x' $t)\x00\x00\x00\x$(printf '%02x' `echo -n "$m"|wc -c`)$m\x00\x00\x00\x00$(printf '%08x' $w|sed 's/../\\x&/g')$(printf '%08x' $h|sed 's/../\\x&/g')$(printf '%08x' $d|sed 's/../\\x&/g')\x00\x00\x00\xff$(printf '%08x' `stat -c '%s' "$i"`|sed 's/../\\x&/g')";cat "$i")|base64 --wrap=0) > i.meta
${FFmpegBin} -y -i ${source} -acodec copy -map 0:0 -map_metadata -1 -metadata title="${title}" -metadata copyright="Diffusée selon les termes dau moins une des licences suivantes : licence Art libre version 1.3 ou ultérieure http://artlibre.org/licence/lal/, licence Creative Commons By Sa version 2.0 ou ultérieure http://creativecommons.org/licenses/by-sa/2.0/fr/ et licence GNU FDL version 1.3 ou ultérieure http://www.gnu.org/licenses/fdl-1.3.html" -metadata artist="April - Cause Commune" -metadata contact="${url}" ${fichiertemp}
${FFmpegBin} -y -i ${fichiertemp} -i i.meta -acodec copy -map 0:0 -map_metadata 1 ${destination}
rm ${fichiertemp}
rm i.meta