Δημοσιεύτηκε: 05 Ιούλ 2009, 21:09
από Ntelispak
Μετατροπή wma σε mp3
Το πρώτο μου sciptάκι. Κυκλοφορούν πολλά αντίστοιχα στο διαδίκτυο αν δεν σας αρέσει η δική μου εκδοχή.
06/07/09: Διόρθωσα λίγο το error handling
Κώδικας: Επιλογή όλων
################################## wma2mp3.sh ##################################
# Author : Karapanagiotis Pantelis #
# Released On : Sunday 05 July 2009 #
# Version : 0.1.1 #
# Desription : Converts all wma files in the current folder to mp3 ones. It #
# is able to convert all files, independently of the characters #
# contained in their names. #
# Dependencies : This script depends on mplayer to decode the original wma to #
# a temporary wav file. Then it uses lame to encode the wav file#
# to a mp3 one. To intall the dependencies in debian derived #
# enviroments use #
# sudo apt-get install mplayer lame #
# Usage : In order to avoid copying the file to every folder you want to#
# use it, just copy it in /usr/local/bin. Give it permission to #
# be executed. Then cd to the desired folder and execute the #
# shell script using just wma2mp3.sh #
# TODO : >>keep track tags >>Let user choose bitrare. >>Enable more #
# conversions #
# COPYRIGHT : This program is free software: you can redistribute it and/or #
# modify it under the terms of the GNU 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 General Public License for more details. #
################################################################################
#!/bin/bash

echo Executing $(basename $0)

#Variable Declarations
converted=0
found=0

#Converting wma to mp3
for i in *.wma; do
found=$(expr $found + 1)
mv "$i" temp.wma
#replace -V 2 with -b 192 for fixed 192 bitrate
mplayer -ao pcm temp.wma -ao pcm:file=temp.wav
lame -h -V 2 temp.wav temp.mp3

if [ $? -eq 0 ]; then
echo "$i" successfully converted to "${i%.wma}.mp3"
converted=$(expr $converted + 1)
else
echo failed recoding "$i"
fi

mv temp.mp3 "${i%.wma}.mp3"
mv temp.wma "$i"
done

#Removing temporary files
rm -r temp.wav

echo $converted\\$found files successfully converted
echo Would you like to remove the files with wma extension? [y\\n]?

#Remove wma file if y is given
while read inputline; do
in="$inputline"
if [ $in == y ] || [ $in = n ]; then
if [ $in == y ]; then
echo Removing all files with wma extension:
find $pwd -name \*.wma -print -delete
fi
break
else
echo Unexpected input sequence. Pleaze try again: [y\\n]?
fi
done

echo Exiting $(basename $0)