On Sat, 15 Feb 2014 12:31:40 -0800
David Guntner <da...@guntner.com> wrote:

> Sharon Kimble grabbed a keyboard and wrote:
> > I am using this script to convert radio programmes downloaded with
> > 'get-iplayer' from '*.m4a' to '*.mp3', and it works very well. 
> > 
> > for i in *.m4a;
> >                     do faad "$i"
> >                             x=`echo "$i"|sed -e 's/.m4a/.wav/'`
> >                             y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
> >                             lame -h -b 192 "$x" "$y"
> >                             rm -f "$x"
> >                     done;
> > 
> > But, there is a problem. They come in this format -
> > '15_Minute_Drama_-_AM_Homes_-_This_Book_Will_Save_Your_Life_Episode_5_b00jdlb8_default.m4a'
> >     
> > How can I lose the '_b00jdlb8_default' section please? It is always
> > in this format but with different letters and numbers in the section
> > before 'default'. 
> > 
> > I have quite a few programmes already converted so I also need to be
> > able to use this ability on them too. I would welcome another script
> > that could perform this please?
> 
> I went for the quick and dirty, assuming that the filenames would
> always be structured as your above example.  Whipped this script up
> (name the file whatever you want), and tested it:
> 
> 
> #!/bin/bash
> for in in *.m4a
> do
>   out=`echo $in|cut -d_ -f 1-15 -`
>   mv $in $out.m4a
> done
> 
> 
> The -d_ sets "_" as a delimiter between fields, and the "-f 1-15"
> tells it I want to keep fields 1-15 and throw the rest away (since the
> filename goes 15 fields before running into the part that you want to
> be rid of).  Then it does a simple mv command to change the filename,
> appending the .m4a back to the end of the destination filename.
> 
> There's probably a better way of doing this, one that doesn't depend
> on a fixed number of fields, but I haven't had time to research it as
> of yet. :-)
> 
>                --Dave

Thanks Dave, this is what I have -
#!/bin/bash
for in in *.mp3
do
  out=`echo $in|cut -d_ -f 1-15 -`
  mv $in $out.mp3
done

and I've run it three times on the directory, and here is some of the
outcomes -
4_Extra_at_Bletchley_Park_-_4_Extra_at_Bletchley_Park_b03g8lxl_default.mp3.mp3.mp3
15_Minute_Drama_-_AM_Homes_-_This_Book_Will_Save_Your_Life_Episode_2.mp3.mp3
15_Minute_Drama_-_The_Pillow_Book_Time_and_Change_Episode_1_b03brkss_default.mp3.mp3.mp3

So as you see it works sometimes, but its also adding an extra mp3 to
the end of the line each time the script is run, which isn't ideal!

I've been having a look through all of the mp3 files and they all seem
to be _b0, so that is a constant ..... _b0******_default.mp3

But, there are some files, only a very few, in this syntax -
Witness_-_The_Death_of_Chinese_Cockle_Pickers_p01qpr03_default.mp3.mp3.mp3
with _p0 starting off the weird file names.

Thanks
Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
Debian testing, Fluxbox 1.3.5, emacs 24.3.50.1
Registered Linux user 561944

Attachment: signature.asc
Description: PGP signature

Reply via email to