Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Nov 2001 09:22:48 -0700
From:      "Totally Jayyness" <Jayyness@mindspring.com>
To:        "Mike Meyer" <mwm@mired.org>, "Devin Smith" <devin-freebsdquestions@rintrah.org>, <jhoward@ensynch.com>
Cc:        <questions@freebsd.org>
Subject:   Re: Scripting Problems please help
Message-ID:  <002401c17696$972dd5e0$0300a8c0@jayyness.com>
References:  <15362.21804.774942.105080@guru.mired.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Thanks so much for the help guys.  I will try that while/read combo.

I currently have a script that will build a list of all the mp3 files and
them parse them to a playlist.  It is fairly simple but it gets that job
done.

# Parse mp3 files into m3u playlist
find /mp3 -iname "*.mp3" > /mp3/allsongsbydir.txt
sed -e 's;/mp3;http:12.159.64.5;' -e 's/ /%20/g' /mp3/allsongsbydir.txt >
/mp3/allsongs.m3u

So if I touched up that while/read, I should have something like this?

#!/bin/sh
find /usr/test -type d -print |
while read songs do
    (cd "$songs"; find -iname "*.mp3" > "$songs.m3u")
done

 ok, cool... I hope that is right.  Can't wait to try it.

Hmmm, ok, this looks like it will put just the songs in the output file,
though, in order for the playlist to work, it needs the path to the file
also... so I make this change...

(find "$songs" -iname "*.mp3" > "$songs.m3u")

And I think that puts me right back into the same problem as before, haven't
real time tested it yet. Will do that as soon as I can and see what I get,
in both formats.  If worse comes to worse, I will build all the songs.m3u
files in each directory... then figure out how to script adding the
directory path in front of each song in the .m3u files.

----- Original Message -----
From: "Mike Meyer" <mwm@mired.org>
To: "Devin Smith" <devin-freebsdquestions@rintrah.org>
Cc: <questions@freebsd.org>
Sent: Monday, November 26, 2001 7:43 AM
Subject: Re: Scripting Problems please help


> Devin Smith <devin-freebsdquestions@rintrah.org> types:
> > [snip]
> > > > What I woudl like to do is have a script search each of the
directories =
> > > > for mp3 files and dump that output into a .m3u (playlist file) in
it.  =
> > > > for example..
> > >
> > > #!/bin/sh
> > > find . -type d -print |
> > > while read x
> > >   do
> > >     (cd "$x"; ls *.mp3 > "$x.m3u")
> > >   done
> >
> > Might I suggest the following small changes, assuming you want *all* the
mp3
> > files listed in one playlist.
> >
> > #!/bin/sh
> > find . -type d -print |
> > while read x
> >   do
> >     (cd "$x"; ls | grep -i mp3 >> "~/playlist.m3u")
> >   done
> >
> > which also has the advantage of listing files which end in uppercase or
mixed case, i.e. song.MP3 or song.Mp3.
>
> Ah - good point; the "grep -i" instead of ls'ing for just the thing
> you want in one case. You could also use "ls *.[Mm][Pp]3". You do need
> to change it to "grep -i 'mp3$' to avoid false positives, though.
>
> However, if you just want one big playlist, why fool with the read
> loop at all:
>
> find . -name '*.[Mm][Pp]3' | sed 's;^.*/;;' > ~/playlist.m3u
> or
> find . -type f | sed -n -e 's;^.*/;;' -e '/[Mm][Pp]3$/p' > ~/playlist.m3u
> or
> find . -type f | grep -i 'mp3$' | sed 's;^.*/;;' > ~/playlist.m3u
> or
> ...
>
> Oh yeah, while I'm here - it's best to capture the output of a while
> loop directly, not by appending to a file in the middle of the
> loop. That keeps you from getting fouled up if you try and run it a
> second time:
>
> find . -type d |
> while read x
>   do
>     (cd "$x"; ls)
>   done | grep -i 'mp3$' > ~/playlist.m3u
>
> I moved the grep outside the loop so you only run it once while I was
> at it.
>
> <mike
> --
> Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more
information.
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?002401c17696$972dd5e0$0300a8c0>