Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old December 29th, 2007   #1
picpak
Dipped in Ubuntu
 
picpak's Avatar
 
Join Date: May 2005
Location: Cydonia
My beans are hidden!
Ubuntu 9.04 Jaunty Jackalope
Script: Easily change quality of MP3 files

DISCLAIMER: I don't want this topic turning into a discussion of how bad it is to turn a low quality mp3 into an even lower quality mp3. I don't want to "kill" their mp3s; I want to provide them with a solution to a very viable problem. Maybe they're running low on disk space, or need smaller files for their mp3 player.

Intro:

I for one got very tired of having to always type lame -b 128 etc, etc. into the terminal each time I wanted to change the quality of an mp3. Sure, there's http://www.media-convert.com/ , but that lags our internet. So I whipped up this script.

Installation for Nautilus

Installation for the default file manager in Ubuntu.

1) Download mp3Convert by downloading the attachment at the bottom of this post.

(Alternatively, you can get the code right here:

Code:
#!/bin/bash

quality=128
title=Converting
file=$@

if [ "$file" ]; then
cd `pwd`
lame -b $quality "$file" 2>&1 | awk -vRS='\r' '(NR>3){gsub(/[()%|]/," ");print $2; fflush();}' | zenity --progress --auto-close --auto-kill --title="$title" --text="$title $file at $quality kbps to $file.mp3"
fi
Copy and paste it into the Text Editor and save it as ~/mp3Convert.sh.)

2) Open up a terminal (Applications > Accessories > Terminal) and put the script into ~/.gnome2/nautilus-scripts (the folder Nautilus checks to find any scripts):

Code:
mv mp3Convert.sh ~/.gnome2/nautilus-scripts
3) Make the script executable so that Nautilus will detect it.

Code:
chmod 740 ~/.gnome2/nautilus-scripts/mp3Convert.sh
All done! Now you can right click an mp3 file and go to Scripts > mp3Convert.sh.

Installation for Thunar

Installation for the default file manager in Xubuntu.

1) Download mp3Convert by downloading the attachment at the bottom of this post.

(Alternatively, you can get the code right here:

Code:
#!/bin/bash

quality=128
title=Converting
file=$@

if [ "$file" ]; then
cd `pwd`
lame -b $quality "$file" 2>&1 | awk -vRS='\r' '(NR>3){gsub(/[()%|]/," ");print $2; fflush();}' | zenity --progress --auto-close --auto-kill --title="$title" --text="$title $file at $quality kbps to $file.mp3"
fi
Copy and paste it into Mousepad and save it as ~/mp3Convert.sh.)

2) Open up a terminal (Xfce Menu > Accessories > Terminal) and put the script into ~/.config/Thunar/actions (not needed, but it's a nice clean place to put it):

Code:
mkdir -p ~/.config/Thunar/actions
mv mp3Convert.sh ~/.config/Thunar/actions
3) Make the script executable:

Code:
chmod 740 ~/.config/Thunar/actions/mp3Convert.sh
3) Now go to Edit > Configure custom actions.... Click the Add (plus) sign and put in the following:

a) Under the Basic tab:

Name: mp3Convert.sh
Command: ~/.config/Thunar/actions/mp3Convert.sh %f

b) Under the Appearance Conditions tab:

Put a checkmark next to Audio files. Click Ok and exit out of the actions manager.

Now you can right click an mp3 file and go to mp3Convert.sh.

Configuration

By default it converts files to 128kbps, which I know isn't everyone's cup of tea. So you can edit ~/.gnome2/nautilus-actions/mp3Convert.sh (or ~/.config/Thunar/actions/mp3Convert.sh, depending on where you put it) by doing

Code:
gedit ~/.gnome2/nautilus-actions/mp3Convert.sh
(or, mousepad ~/.config/Thunar/actions/mp3Convert.sh)

and changing line 3 from

Code:
quality=128
to

Code:
quality=192
Or, whatever quality you prefer. Save and exit.

Enjoy!
Attached Files
File Type: sh mp3Convert.sh (293 Bytes, 36 views)
__________________

Last edited by picpak; January 2nd, 2008 at 10:46 AM..
picpak is offline   Reply With Quote
Old February 3rd, 2008   #2
Mary.Riley
5 Cups of Ubuntu
 
Mary.Riley's Avatar
 
Join Date: Sep 2007
Location: Ann Arbor, MI
Beans: 19
Ubuntu 7.10 Gutsy Gibbon
Re: Script: Easily change quality of MP3 files

Is there a way to do this for Konqueror as well?
__________________
When I first started, it was hard finding Ubuntu applications to show the true extent of Linux and open development. An list with screenshots and videos would have made the process easier. See apps like GNOME Do and Brightside at The Daily Ubuntu.
Mary.Riley is offline   Reply With Quote
Old February 9th, 2008   #3
_march_
5 Cups of Ubuntu
 
_march_'s Avatar
 
Join Date: Oct 2005
My beans are hidden!
Ubuntu 9.04 Jaunty Jackalope
Re: Script: Easily change quality of MP3 files

Thanks for your Skript
Just added it in our Wiki
_march_ is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:38 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry