Bonjour,
Voici un petit script pour convertir des fichiers audio (tout format pris en charge par gstreamer) en mp3 au debit de son choix.
A mettre dans ~/.gnome2/nautilus-scripts/Convertir en mp3 (et en executable..)
Apres il vous suffit dans Nautilus de selectionner les fichiers a convertir et click droit (script/Convertir en mp3)
Il n'y a pas besoin de se trouver "dans" le repertoire ou les fichiers sont.. on peut les selectionner n'importe ou.
#!/bin/bash
# dependances: zenity gstreamer-tools
LOC=$(zenity --file-selection --directory --title="Selectionner un repertoire") || exit
RATE=$(zenity --list --radiolist \
--height=400 \
--text="debit en kb/s" --title="Selection du debit mp3" \
--column="Selection" --column="Debit" \
FALSE 32 FALSE 48 FALSE 56 FALSE 64 FALSE 80 FALSE 96 FALSE 112 TRUE 128 FALSE 160 FALSE 192 FALSE 224 FALSE 256 FALSE 320 \
) || exit
IFS=$'\n'
for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
TARGET="$(basename $FILENAME)"
TARGET=${TARGET%.*}.mp3
if [ -e "$LOC"/"$TARGET" ]
then
zenity --error --text="Echec: $LOC"/"$TARGET existe deja."
else
{ gst-launch filesrc location="$FILENAME" ! decodebin ! audioconvert ! lame bitrate=$RATE ! filesink location="$LOC"/"$TARGET"; \
echo Termine. ; } \
| zenity --text-info --title "MP3 conversion output" --width=500 --height=500
fi
done
Edit:
Ci-dessous, version amelioree prenant en charge les sous-repertoires et les tags ID3... Lire les commentaires dans l'entete pour voir les dependances...
#!/bin/bash
#
# dependancies:
# zenity
# gstreamer0.10-plugins-ugly-multiverse
# gstreamer-tools
# the deb at http://home.wanadoo.nl/squell/id3.html for and id3 command line tool.
#
# Usage: To use in Nautilus
# You select files and directorie in Nautilus, then you right click, script/Convert to mp3...
# A first dialog will ask you where to put the converted files
# A second one will let you select the bit rate
# Then a progression bar will appear.
# A log file ~/mp3-convert.log will be created.
#
LOGFILE=~/mp3-convert.log
LOC=$(zenity --file-selection --directory --title="Directory to receive the converted audio") || exit
RATE=$(zenity --list --radiolist \
--height=400 \
--text="bitrate in kb/s" --title="Select mp3 bit rate" \
--column="Select" --column="Bit rate" \
FALSE 32 FALSE 48 FALSE 56 FALSE 64 FALSE 80 FALSE 96 FALSE 112 TRUE 128 FALSE 160 FALSE 192 FALSE 224 FALSE 256 FALSE 320 \
) || exit
(
IFS=$'\n'
TOTAL=0
NB=0
# Checking how many files there are to process
for SELECTED in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
if [ -f "$SELECTED" ]
then
let TOTAL+=1
elif [ -d "$SELECTED" ]
then
for FILENAME in $(find "$SELECTED" -type f -printf "%p\n")
do
let TOTAL+=1
done
fi
done
function audio-convert
{
echo -e "#Processing $(basename $1)"
echo "$1 -> $2"
gst-launch filesrc location="$1" ! decodebin ! audioconvert ! lame bitrate=$RATE ! filesink location="$2" 2>&1
id3 -D "$1" -1 -2 "$2" 2>&1
}
function show_progress
{
let NB+=97/TOTAL
echo $NB
}
for SELECTED in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
echo 1
if [ -f "$SELECTED" ]
then
TARGET="$(basename $SELECTED)"
TARGET=${TARGET%.*}.mp3
if [ -e "$LOC/$TARGET" ]
then
echo -e "\nWarning: $LOC/$TARGET already exist, did not overwrite it." >$LOGFILE
else
audio-convert "$SELECTED" "$LOC/$TARGET"
fi
show_progress
elif [ -d "$SELECTED" ]
then
TARGET_DIR="$LOC/${SELECTED##*/}"
if [ ! -d "$TARGET_DIR" ]
then
mkdir -p "$TARGET_DIR"
fi
for FILENAME in $(find "$SELECTED" -type f -printf "%p\n")
do
THEDIR=${FILENAME%/*}
THEDIR=${THEDIR:${#SELECTED}}
THEDIR="$TARGET_DIR$THEDIR"
if [ ! -d "$THEDIR" ]
then
mkdir -p "$THEDIR"
fi
TARGET="$(basename $FILENAME)"
TARGET=${TARGET%.*}.mp3
if [ -e "$THEDIR/$TARGET" ]
then
echo -e "\nWarning: $THEDIR/$TARGET already exist, did not overwrite it." >$LOGFILE
else
audio-convert "$FILENAME" "$THEDIR/$TARGET"
if [ ! -s "$THEDIR/$TARGET" ]
then
echo "It probably was not audio, copying instead."
rm "$THEDIR/$TARGET"
cp -a -- "$FILENAME" "$THEDIR/$(basename $FILENAME)"
fi
fi
show_progress
done
fi
done
echo 100
) | tee $LOGFILE | zenity --progress --auto-close
zenity --text-info --title='Conversion log' --filename=$LOGFILE