#!/bin/bash # Copyright (C) 2019 Quentin GIBEAUX # Copyright (C) 2019 Frédéric Couchet # # This file is part of lav-outils from "April/Libre à vous !" # # This script is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . usage() { echo "$0 -s source_file -d destination_file -u https://... -t \"title\" -p path/to/ffmpeg/binary -y \"year\" -m \"yes or no\""; exit 0; } [ $# -eq 0 ] && usage while getopts "s:d:u:t:p:y:m:h" arg; do case $arg in s) source=${OPTARG} ;; d) destination=${OPTARG} ;; u) url=${OPTARG} ;; t) title=${OPTARG} ;; p) FFmpegBin=${OPTARG} ;; y) year=${OPTARG} ;; m) mp3=${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" fichiertempogg="$(command mktemp -t "tmp.XXXXXXXXXX.ogg")" fichiertempmp3="$(command mktemp -t "tmp.XXXXXXXXXX.mp3")" text=$(printf "Émission « Libre à vous ! » de l'April diffusée sur radio la « Cause Commune ».\n\nPour en savoir plus https://libreavous.org et https://cause-commune.fm\n\nAdresse d'origine du fichier audio ${url}\n\nFichier diffusé selon les termes d’au moins une des licences suivantes : licence Art libre version 1.3 ou ultérieure https://artlibre.org/licence/lal/, licence Creative Commons By Sa version 2.0 ou ultérieure https://creativecommons.org/licenses/by-sa/2.0/fr/ et licence GNU FDL version 1.3 ou ultérieure https://www.gnu.org/licenses/fdl-1.3.html.") (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 # Generation du fichier OGG avec l'image de pochette (cover) et les métadonnées ${FFmpegBin} -y -i ${source} -acodec copy -map 0:0 -map_metadata -1 -metadata title="${title}" -metadata license="Diffusée selon les termes d’au moins une des licences suivantes : licence Art libre version 1.3 ou ultérieure https://artlibre.org/licence/lal/, licence Creative Commons By Sa version 2.0 ou ultérieure https://creativecommons.org/licenses/by-sa/2.0/fr/ et licence GNU FDL version 1.3 ou ultérieure https://www.gnu.org/licenses/fdl-1.3.html Pour vérifier voir https://libreavous.org" -metadata artist="April - Cause Commune" -metadata copyright="April - Cause Commune" -metadata genre="Podcast" -metadata contact="https://libreavous.org" -metadata description="${text}" ${fichiertempogg} ${FFmpegBin} -y -i ${fichiertempogg} -i i.meta -acodec copy -map 0:0 -map_metadata 1 ${destination}.ogg if [ "$mp3" = "yes" ]; then # Generation du fichier MP3 avec conservation de l'image de pochette (cover), des métadonnées en deux passes # Conservation de l'image de pochette (cover) et des métadonnées ${FFmpegBin} -y -i ${destination}.ogg -map_metadata 0:s:0 ${fichiertempmp3} # Passe pour avoir le champ Duration dans le fichier (qui n'est pas présent suite à la conversion de OGG en MP3) ${FFmpegBin} -y -i ${fichiertempmp3} -acodec copy ${destination}.mp3 # Mise à jour des métadonnées pour tenir compte des métadonnées MP3 eyeD3 --user-text-frame="LICENSE:" ${destination}.mp3 eyeD3 --user-text-frame="comment:" ${destination}.mp3 eyeD3 -c "`echo "${text}"|sed '1,$s/.ogg/.mp3/'`" ${destination}.mp3 eyeD3 --user-text-frame="WOAF:`echo "${url}"|sed 's/:/\\\:/' |sed 's/.ogg/.mp3/'`" ${destination}.mp3 eyeD3 --text-frame="TCOP:${year} April - Cause Commune Fichier diffusé selon les termes d’au moins une des licences suivantes \: licence Art libre version 1.3 ou ultérieure https\://artlibre.org/licence/lal/, licence Creative Commons By Sa version 2.0 ou ultérieure https\://creativecommons.org/licenses/by-sa/2.0/fr/ et licence GNU FDL version 1.3 ou ultérieure https\://www.gnu.org/licenses/fdl-1.3.html. Pour vérifier voir https\://libreavous.org" ${destination}.mp3 fi rm ${fichiertempogg} rm ${fichiertempmp3} rm i.meta