View previous topic :: View next topic |
Author |
Message |
Temet Advocate
Joined: 14 Mar 2006 Posts: 2586 Location: 92
|
Posted: Wed Aug 30, 2006 12:42 am Post subject: [scripts] miniatures d'image et conversion ogg -> mp3 |
|
|
Bon, je ne suis pas certain de l'utilité de mes deux petits scripts ici mais après tout, je partage ... si ça ne fait pas de bien, ça ne fera pas de mal.
Le premier script sert à générer une miniature d'une image comme chez les hébergeurs, mais plutôt utile à ceux qui mettent leurs images sur leur FTP. Il nécessite ImageMagick.
Ca donne quelque chose comme ça : http://goondy.free.fr/Images/gentop-thumb.png
(la balise "img" ne marche pas ici o_O')
Si vous l'appelez "genthumb" comme moi, vous pouvez faire :
Code: | genthumb image.png
genthumb image1.png image2.png image3.jpg
genthumb *.png |
Code: | #!/bin/bash
# thanks to Remi, Anvil & NaiosKAE The Korrigan
# verifying usage
if [ "$#" = "0" -o "$1" = "-h" -o "$1" = "--help" ]; then
echo Usage : $(basename $0) image [ image ... ]
echo Used to generate thumbnails of a list of images.
exit 1
fi
# loop that enables the treatment of a list of images
for i in "$@"; do
# verifying file
if [ -f "$i" ]; then
# get image infos
iinfos=$(identify -format "%m:%wx%h:%t:%e:%b" "$i")
# get image type
itype=$(echo $iinfos | awk -F":" '{print $1}')
# get image resolution
resolution=$(echo $iinfos | awk -F":" '{print $2}')
# get image name, without extension
name=$(echo $iinfos | awk -F":" '{print $3}')
# get extension
extension=$(echo $iinfos | awk -F":" '{print $4}')
# get image size
size=$(echo $iinfos | awk -F":" '{print $5}')
# convert size to human readable format
if [ $size -ge 1048576 ]; then
sizeh="$(( size / 1048576 )) Mo"
elif [ $size -ge 1024 ]; then
sizeh="$(( size / 1024 )) Ko"
else
sizeh="$size o"
fi
# resize image and add infos
convert "$i" -resize 400x200 -gravity South -background Black -fill white -splice 0x18 -draw "text 0,2 '$itype : $resolution - $sizeh'" "$name"-thumb.$extension
else
echo "$i" : file does not exist
fi
done |
--------------------------------------------------
Pour le deuxième script, mon baladeur ne lit pas les ogg. Jusqu'à présent je codais mes CDs en mp3 à cause de ça. Toutefois, mon coté libriste gagnant peu à peu du terrain, j'ai encodé mes derniers CDs en ogg.
J'ai donc fait un petit script pour convertir les ogg en mp3. De plus, mon baladeur lit les chansons par ordre alphabétique, il faut donc le numéro de piste en premier pour avoir les chansons dans l'ordre.
Le script s'utilise des façons suivantes (si vous l'appelez ibeadogg) :
Code: | ibeadogg chanson1.ogg chanson2.ogg chanson3.ogg ...
ibeadogg *.ogg
ibeadogg répertoire1 répertoire2 chanson1.ogg chanson2.ogg ... |
Les fichiers sont encodés dans le home, dans un dossier "artist - titre de l'album".
Code: | #!/bin/bash
# used to convert ogg files in mp3
# requires ogg123, lame & taginfo
# usage
if [ "$#" = "0" -o "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage : $(basename $0) file [ file ... ]"
echo "Used to convert a list of ogg files in mp3. Directories containing ogg files are allowed."
exit 1
fi
# function that converts an ogg file in a mp3 file
oggtomp3()
{
ftype=$(file -b "$1" | awk -F", " '{print $1}') # type of the file
if [ "$ftype" = "Ogg data" ]; then
echo "Processing : $1"
artist=$(taginfo "$1" | grep ARTIST | tr -d "\"" | awk -F"=" '{print $2}')
album=$(taginfo "$1" | grep ALBUM | tr -d "\"" | awk -F"=" '{print $2}')
title=$(taginfo "$1" | grep TITLE | tr -d "\"" | awk -F"=" '{print $2}')
track=$(taginfo "$1" | grep TRACK | tr -d "\"" | awk -F"=" '{print $2}')
if ! [ -d "$HOME/$artist - $album (mp3)" ]; then
mkdir "$HOME/$artist - $album (mp3)"
fi
if [ $track -le 9 ]; then
outfile="$HOME/$artist - $album (mp3)/0$track - $artist - $title.mp3"
else
outfile="$HOME/$artist - $album (mp3)/$track - $artist - $title.mp3"
fi
ogg123 -q --device=wav "$1" -f - | lame --quiet -m j -q 5 --cbr -b 128 \
--tt "$title" --ta "$artist" --tl "$album" --tn "$track" - "$outfile"
else
echo "File is not ogg file, skipping it."
fi
}
for i in "$@"; do
# checking file
if [ -d "$i" ]; then
# processing a directory
for j in "$i"/*.ogg; do
if [ -f "$j" ]; then
oggtomp3 "$j"
fi
done
elif [ -f "$i" ]; then
# processing a file
oggtomp3 "$i"
else
echo "File does not exist, skipping it."
fi
done
echo "Done." |
Last edited by Temet on Sat Sep 02, 2006 11:52 am; edited 1 time in total |
|
Back to top |
|
|
gaaruto n00b
Joined: 13 Apr 2005 Posts: 13 Location: France
|
Posted: Thu Aug 31, 2006 6:29 pm Post subject: |
|
|
Merci bien Temet, je connaissais déjà mais bon, ca fait plaisir de voir ca ici
Tcho ma poule |
|
Back to top |
|
|
Temet Advocate
Joined: 14 Mar 2006 Posts: 2586 Location: 92
|
Posted: Sat Sep 02, 2006 12:28 am Post subject: |
|
|
Enlight m'a fait remarqué que l'emploi des awk est excessif dans le premier (dans le deuxième aussi mais bon), on a donc cherché comment remplacer.
Voilà:
Code: | #!/bin/bash
# thanks to Remi, Anvil & NaiosKAE The Korrigan
# verifying usage
if [ "$#" = "0" -o "$1" = "-h" -o "$1" = "--help" ]; then
echo Usage : $(basename $0) image [ image ... ]
echo Used to generate thumbnails of a list of images.
exit 1
fi
# loop that enables the treatment of a list of images
for i in "$@"; do
# verifying file
if ! [ -f "$i" ]; then
echo "$i" : file does not exist
exit 1
fi
# get image infos
iinfos=($(identify -format "%m %wx%h %e %b" "$i"))
itype=${iinfos[0]}
resolution=${iinfos[1]}
extension=${iinfos[2]}
isize=${iinfos[3]}
name=$(basename "$i" .${iinfos[2]})
# convert size to human readable format
if [ $isize -ge 1048576 ]; then
sizeh="$(( isize / 1048576 )) Mo"
elif [ $isize -ge 1024 ]; then
sizeh="$(( isize / 1024 )) Ko"
else
sizeh="$isize o"
fi
# resize image and add infos
convert "$i" -resize 300x182 -gravity South -background Black -fill \
white -splice 0x18 -draw "text 0,2 '$itype : $resolution - $sizeh'" \
"$name"-thumb.$extension
done
|
Coté perfs, c'est pareil (j'ai vérifié avec un time, c'est un poil plus rapide même, mais négligeable).
Last edited by Temet on Sat Sep 02, 2006 11:49 am; edited 2 times in total |
|
Back to top |
|
|
fb99 l33t
Joined: 09 Apr 2003 Posts: 998 Location: Le Locle (Suisse,Neuchâtel)
|
Posted: Sat Sep 02, 2006 8:26 am Post subject: |
|
|
rien ne vaut un peu d'exercice mano, mais chercher simplifie parfois la vie Code: | * media-sound/mp32ogg
Latest version available: 0.11-r4
Latest version installed: [ Not Installed ]
Size of downloaded files: 9 kB
Homepage: http://faceprint.com/code/
Description: A perl script to convert MP3 files to Ogg Vorbis files.
License: Artistic
* media-sound/ogg2mp3
Latest version available: 0.5
Latest version installed: [ Not Installed ]
Size of downloaded files: 12 kB
Homepage: http://amor.cms.hu-berlin.de/~h0444y2j/linux.html
Description: A perl script to convert Ogg Vorbis files to MP3 files.
License: GPL-2
|
au cas ou le tiens buggerais, enjoy _________________ L'ami aime en tout temps, et dans le malheur il se montre un frère ( Prov. 17,17 )
L'insensé même, quand il se tait, passe pour sage ( Prov. 17;28a ) |
|
Back to top |
|
|
Temet Advocate
Joined: 14 Mar 2006 Posts: 2586 Location: 92
|
Posted: Sat Sep 02, 2006 11:49 am Post subject: |
|
|
Ouais je le savais, mais la conversion c'est une seule ligne dans le script, et comme tout le reste est bien bash, j'avais pas envie de foutre un script perl et d'être obligé de l'installer pour ça |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|