Help - Search - Members - Calendar
Full Version: Mediaplayer Playlist Maker Script
OESF Forums > General Forums > General Support and Discussion > Software
steven999
Hi All,

I've had a number of issues of finding a good system for listening to MP3's on my 5600. I purchased TKCPlayer but after it crashing so many times and it not being able to read ID3 tags in most of my MP3's, I gave up on it. Kino2 was alright but quirky, and so I went back to using Sharp Mediaplayer. The problem for me is that having a number of albums with files starting with "1." or "2." etc., it's hard to look through the list of files that are part of an album and then make a playlist as the files get interspersed. So I finally had some free time and wrote a quick python script that will look into a few roots (directories to walk) and for every file in every directory and subdirectory, add it to the Mediaplayer playlist (well, the playlist gets replaced with the new one). This ends up having the files in each directory added in alphabetic order. I find that then whenever I add or remove mp3's to my cf or sd card, I just rerun the script, open MediaPlayer, and then go to the album or file I want to listen to in the playlist.

The script and Mediaplayer.in file is attached (as zip) and if you're going to give it a try you will need to configure the roots in the python file as well as copy MediaPlayer.in file to ~/Settings/ (or change the python script to where you put MediaPlayer.in).

To run the script, you'll need python 2.3 installed and just type:

python playlist.py

Please backup your Mediaplayer.xml file before trying, and I'm not responsible for you trying it and not backing up before using it. =)

Thanks and hope you all find it useful!
steven
gdog
steven999,

Great job! I just recently started using my C1K for an MP3 player and am planning on writing a similar script in Perl. Mine will be a bit different though as the Genre tag did not come over when I converted the cuts from WMA to MP3, and so I plan to allow for command line options for Groups, and/or Album and/or concatenation vs. overwriting (the last so that I can add to and existing list if I want as opposed to overwriting).

This is off-topic but I'll keep it short. I was amazed at the increased sound quality of MP3 over WMA at the same bitrate.
steven999
Hi gdog,

Thanks! I'm really happy with the script and since I don't have *too* much space (512 CF and SD cards) the script is doing the job just fine. I think if I had a Microdrive or larger space, I might want some of the features you are thinking to implement. But if you go ahead and implement all that and post it here, I just might have to use it. =)

Thanks and good luck!
steven
samot
I was planing to make a similar shell script but in this case it just will add the name of the directory where the mp3 is standing to the mp3 name.

in example:

i've got an mp3 in the following directory:

/mnt/card/music/tool/04-lateralus.mp3

the script should rename all the mp3's in tha directory as

/mnt/card/music/tool/tool-04-lateralus.mp3

so sorting alphabeticaly in media player would make the tracks from the same artis stick together and in track oreder. If you have various albums of the same artist you should also add the album to the mp3 name... bit anoying and long

imagine:

"the chemical brothers-dig your own hole-11-Private Psychedelic Reel.mp3" ... a bit too long

The first thing I tryed was "mv * tool-*" which obviewly didn't work, finally i tryed with a script. The script which is NOT WORKING is:

CODE
#!/bin/sh
MUSIC=/mnt/card/Documents/Music

cd $MUSIC

for dir in ls
do
   for file in ls *.mp3
   do
       mv '$dir/$file' '$dir/$dir-$file'
   done
done


if anyone could help me it would be great, i'm not verry skilled at bash scripting


DON'T TRY THE SCRIPT AS IS, IT'S GOING TO MAKE A MESS WITH YOUR FILES!!!

Thanks
grog
QUOTE(samot @ May 14 2006, 01:22 PM)
I was planing to make a similar shell script but in this case it just will add the name of the directory where the mp3 is standing to the mp3 name.

in example:

i've got an mp3 in the following directory:

/mnt/card/music/tool/04-lateralus.mp3

the script should rename all the mp3's in tha directory as

/mnt/card/music/tool/tool-04-lateralus.mp3
*


CODE
#!/bin/sh
MUSIC=/mnt/card/Documents/Music

cd $MUSIC

for dir in *; do
   [ ! -d $dir ] && continue
   for file in $dir/*.mp3; do
       mv $file $dir/$dir-${file##*/}
   done
done

exit 0


HTH
samot
wow tha was fast!!! i'll try it!!


Thanks
grog
QUOTE(samot @ May 14 2006, 01:47 PM)
wow tha was fast!!!
The midnight scripter strikes again!!! smile.gif
QUOTE
i'll try it!! Thanks
*
You're welcome
samot
ho!! it seems to mess when the mp3 name gots a blank space

ie: when traying to rename

01 Ooh la la.mp3

i get

mv: unable to rename `Goldfrap/01': No such file or directory
mv: unable to rename `Ooh': No such file or directory
mv: unable to rename `la': No such file or directory
mv: unable to rename `la.mp3': No such file or directory

Thanks
grog
QUOTE(samot @ May 14 2006, 01:56 PM)
it seems to mess when the mp3 name gots a blank space
*
Then quote the variables for the mv command:

CODE
mv "$file" "$dir/$dir-${file##*/}"

(SWOOP!!) smile.gif
samot
Bingo!! it works.

What i'm now thinkig is that if I run the script once, then I ad a new mp3 album to my cf and run it for the second time i'll get double renamed files!! But never mind.

Thanks Midnight Scripter!!! you are my hero!!!
samot
do you think this may do? I added grep on " for file in ($dir/*.mp3 |grep -v $dir); do"


CODE
MUSIC=/mnt/card/Documents/Music

cd $MUSIC

for dir in *; do
  [ ! -d $dir ] && continue
  for file in ($dir/*.mp3 |grep -v "$dir"); do
      mv "$file" "$dir/$dir-${file##*/}"
  done
done

exit 0
grog
QUOTE(samot @ May 14 2006, 02:33 PM)
What i'm now thinkig is that if I run the script once, then I ad a new mp3 album to my cf and run it for the second time i'll get double renamed files!! do you think this may do?

CODE
for file in ($dir/*.mp3 | grep -v "$dir/$dir"); do
*

Close, young padawan smile.gif. The pipe won't work that way, and you would skip over _all_ the files with that pattern. The pipe has to be fed by another program & the pattern has to be more precise.

CODE
for file in (ls -1 $dir/*.mp3 | grep -v "$dir/$dir"); do

keephavingfun!
samot
QUOTE(grog @ May 14 2006, 02:11 PM)
CODE
for file in (ls -1 $dir/*.mp3 | grep -v "$dir/$dir"); do

keephavingfun!
*


Sensei, I think you are missing a "$" before "(", anyway, i added it and now and y get the same problem with the spaces.

If I write

CODE
for file in "$(ls -1 $dir/*.mp3 | grep -v "$dir/$dir")"; do


I get

CODE
bash-2.05$ ./music.sh  
mv: unable to rename `Goldfrap/01 Ooh la la.mp3
Goldfrap/02 Lovely 2 c u.mp3
Goldfrap/03 Ride a white horse.mp3
Goldfrap/04 You never know.mp3
Goldfrap/05 Let it take you.mp3
Goldfrap/06 Fly me away.mp3
Goldfrap/07 Slide in.mp3
Goldfrap/08 Koko.mp3
Goldfrap/10 Time out from the world.mp3
Goldfrap/11 Number 1.mp3
Goldfrap/12 Satin Chic.mp3': No such file or directory


If I write

CODE
for file in $(ls -1 "$dir/*.mp3" | grep -v "$dir/$dir"); do


I get

CODE
ls: Goldfrap/*.mp3: No such file or directory


using "$dir/"*".mp3" brings back the first space problem huh.gif

Thanks smile.gif
grog
Sorry for the delay. Even the midnight scipter has to 'service' his alter egos (husband, father, employee, pet owner, ... ) smile.gif

QUOTE(samot @ May 14 2006, 04:43 PM)
QUOTE(grog @ May 14 2006, 02:11 PM)
CODE
for file in (ls -1 $dir/*.mp3 | grep -v "$dir/$dir"); do

keephavingfun!
*


Sensei, I think you are missing a "$" before "(", anyway, i added it and now and y get the same problem with the spaces.

That was just a test, joung one. You passed (this time) smile.gif

QUOTE
If I write

CODE
for file in "$(ls -1 $dir/*.mp3 | grep -v "$dir/$dir")"; do


I get

CODE
bash-2.05$ ./music.sh  
mv: unable to rename `Goldfrap/01 Ooh la la.mp3
Goldfrap/02 Lovely 2 c u.mp3
Goldfrap/03 Ride a white horse.mp3
Goldfrap/04 You never know.mp3
Goldfrap/05 Let it take you.mp3
Goldfrap/06 Fly me away.mp3
Goldfrap/07 Slide in.mp3
Goldfrap/08 Koko.mp3
Goldfrap/10 Time out from the world.mp3
Goldfrap/11 Number 1.mp3
Goldfrap/12 Satin Chic.mp3': No such file or directory


If I write

CODE
for file in $(ls -1 "$dir/*.mp3" | grep -v "$dir/$dir"); do


I get

CODE
ls: Goldfrap/*.mp3: No such file or directory


using "$dir/"*".mp3" brings back the first space problem  huh.gif

Thanks smile.gif
*

Not sure what's going on there, so we'll avoid that & go in the back door

CODE
#!/bin/sh

MUSIC=/mnt/card/Documents/Music

cd $MUSIC

for dir in *; do
 [ ! -d $dir ] && continue
 ls -1 $dir/*.mp3 | grep -v "$dir/$dir" | while read line; do
     (set -x; mv "$line" "$dir/$dir-${line##*/}")
 done
done

exit 0


In UNIX, there's always more than one way to cat a skin smile.gif
enjoy
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2015 Invision Power Services, Inc.