Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (4) </ 1 2 [3] 4 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: MP3 transcoding in Emelfm, syntax challenge< Next Oldest | Next Newest >
cbagger01 Offline





Group: Members
Posts: 4264
Joined: Oct. 2003
Posted: April 16 2005,03:33 QUOTE

I try to avoid spaces in filenames as much as possible.

HOWEVER, when you are working with mp3 files that are ripped automatically from audio CDs using a ripper program that connects to the Internet to retrieve the artist / album / songname information, the Internet database will generate output filenames that will contain spaces in between the words from the song title.

So unless you also write a little utility script that converts all of your " " into "_" for the filenames, or unless you patch the source code of the ripper program (assuming that it is open source) and recompile, you will be dealing with filenames that contain spaces.

My preference is to make the conversion utility script smart enough to properly handle them but it appears that you and clacker have already done the job :)
Back to top
Profile PM 
cbagger01 Offline





Group: Members
Posts: 4264
Joined: Oct. 2003
Posted: April 16 2005,04:43 QUOTE

I tried fooling around with emelfm a little bit and it does a better job than expected of passing a filename with a space over to the script.

Give this one a try.  You can only convert one file at a time because it passes the output directory down to the script as the second argument.

I did not test it with lame but the rest of the script works fine when I substitute the "cat" command instead of lame.

Code Sample
#!/bin/bash
#
# /opt/tcode/tcode160  -  A small Emelfm script to transcode a single mp3
#                         file into a new 160kb mp3 file in the other directory
#                         window pane.
#
# This new mp3 filetype association action COMMAND should be created in Emelfm:
#
# /opt/tcode/tcode160 %f %D
#
# Do NOT select multiple mp3 files at the same time when using this command.
#
# Script begins here
filename="$1"
output_path="$2"
newfile=`echo $filename | awk -F .mp3 '{print $1}'`
lame --mp3input "$filename" -h -v -b 160 "$output_path/$newfile-160.mp3"
exit
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: April 16 2005,04:55 QUOTE

The "other directory pane" is brilliant.  Very simple and effective way to specify a target directory.

For multiple files, a "for i in %f" loop can work, but in this case it might take some work.  I'm not even sure that works with spaces.
What happens when you do something like this:
for i in "$1"; do
echo "$i"
done
Does it mess up files with spaces? (again, i don't have access to emelfm at the moment.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: April 16 2005,11:52 QUOTE

cbagger01, that's a great idea using the %D to get the path of the directory of the inactive pane.  I modified my button script to use that idea.  Now it handles file names with spaces, multiple file selections, and puts the converted files in the inactive pane's directory.  It' works fine and it's short, but it is a little cryptic:

ls %f | xargs -i lame -S -b 96 "{}" "%D/96-{}"

the ls part puts the file names on separate lines.  %f is the list of selected files in the active emelfm panel.

The xargs command runs the same command for a bunch of files.  xargs -i replaces every occurance of {} and replaces it with the file name.  The files are in quotes to handle files with spaces in there names.

The -S switch in lame keeps lame from using ncurses which filles up the emelfm output window with text and control charecters.  The -b 96 switch sets the quality of the mp3.  I kept the 96-*.mp3 format, although if you're putting the output into a different directory it might not be needed.

It still requires gnu-utils to be loaded first.
Back to top
Profile PM 
cbagger01 Offline





Group: Members
Posts: 4264
Joined: Oct. 2003
Posted: April 17 2005,03:48 QUOTE

I think we have a winner.

Clacker's one line solution should do the trick because ke4nt1 uses gnu-utils most of the time.

If not, a for loop is also an option.

Finally, it is possible to put the whole thing into a script but I would need to double check my bash tutorial.

Basically, you would still pass the %f and %D down to the script and you would detect the total number of arugments passed.

Then you assign the last arugment as the output path and then you loop to (i-1) where i is the total number of arguments.

Or better yet you make the %D your FIRST argument and your %f your second argument and that simplifies things quite a bit.

Something tells me that a person who tries to do this in MSWindows with an MS-DOS batch file would be pulling his hair out :)
Back to top
Profile PM 
15 replies since April 14 2005,19:51 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (4) </ 1 2 [3] 4 >/
reply to topic new topic new poll
Quick Reply: MP3 transcoding in Emelfm

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code