Author Topic: Mediaplayer Playlist Maker Script  (Read 4549 times)

steven999

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« on: December 07, 2005, 04:27:34 pm »
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

  • Full Member
  • ***
  • Posts: 246
    • View Profile
Mediaplayer Playlist Maker Script
« Reply #1 on: December 08, 2005, 07:46:27 pm »
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.
You can tell a lot about a man by the condition of his shoes

steven999

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #2 on: December 08, 2005, 09:26:22 pm »
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

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #3 on: May 14, 2006, 03:22:23 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

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: [Select]
#!/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
« Last Edit: May 14, 2006, 03:36:41 pm by samot »
sl-5500 | WCF12 | SD kingstone 1gb | CF Memorex (Samsung) 64mb | OZ/OPIE (for the moment)

grog

  • Hero Member
  • *****
  • Posts: 692
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #4 on: May 14, 2006, 03:41:01 pm »
Quote
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[div align=\"right\"][a href=\"index.php?act=findpost&pid=127012\"][{POST_SNAPBACK}][/a][/div]

Code: [Select]
#!/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
GROG!

samot

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #5 on: May 14, 2006, 03:47:25 pm »
wow tha was fast!!! i'll try it!!


Thanks
sl-5500 | WCF12 | SD kingstone 1gb | CF Memorex (Samsung) 64mb | OZ/OPIE (for the moment)

grog

  • Hero Member
  • *****
  • Posts: 692
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #6 on: May 14, 2006, 03:53:44 pm »
Quote
wow tha was fast!!!
The midnight scripter strikes again!!!
Quote
i'll try it!! Thanks[div align=\"right\"][a href=\"index.php?act=findpost&pid=127018\"][{POST_SNAPBACK}][/a][/div]
You're welcome
GROG!

samot

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #7 on: May 14, 2006, 03:56:45 pm »
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
« Last Edit: May 14, 2006, 03:57:28 pm by samot »
sl-5500 | WCF12 | SD kingstone 1gb | CF Memorex (Samsung) 64mb | OZ/OPIE (for the moment)

grog

  • Hero Member
  • *****
  • Posts: 692
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #8 on: May 14, 2006, 04:11:56 pm »
Quote
it seems to mess when the mp3 name gots a blank space[div align=\"right\"][a href=\"index.php?act=findpost&pid=127023\"][{POST_SNAPBACK}][/a][/div]
Then quote the variables for the mv command:

Code: [Select]
mv "$file" "$dir/$dir-${file##*/}"(SWOOP!!)
GROG!

samot

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #9 on: May 14, 2006, 04:18:36 pm »
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!!!
sl-5500 | WCF12 | SD kingstone 1gb | CF Memorex (Samsung) 64mb | OZ/OPIE (for the moment)

samot

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #10 on: May 14, 2006, 04:33:24 pm »
do you think this may do? I added grep on   " for file in ($dir/*.mp3 |grep -v $dir); do"


Code: [Select]
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
« Last Edit: May 14, 2006, 05:06:29 pm by samot »
sl-5500 | WCF12 | SD kingstone 1gb | CF Memorex (Samsung) 64mb | OZ/OPIE (for the moment)

grog

  • Hero Member
  • *****
  • Posts: 692
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #11 on: May 14, 2006, 06:11:03 pm »
Quote
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: [Select]
for file in ($dir/*.mp3 | grep -v "$dir/$dir"); do[div align=\"right\"][a href=\"index.php?act=findpost&pid=127029\"][{POST_SNAPBACK}][/a][/div]
Close, young padawan . 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: [Select]
for file in (ls -1 $dir/*.mp3 | grep -v "$dir/$dir"); dokeephavingfun!
GROG!

samot

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #12 on: May 14, 2006, 06:43:07 pm »
Quote
Code: [Select]
for file in (ls -1 $dir/*.mp3 | grep -v "$dir/$dir"); dokeephavingfun!
[div align=\"right\"][a href=\"index.php?act=findpost&pid=127035\"][{POST_SNAPBACK}][/a][/div]

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: [Select]
for file in "$(ls -1 $dir/*.mp3 | grep -v "$dir/$dir")"; do
I get

Code: [Select]
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: [Select]
for file in $(ls -1 "$dir/*.mp3" | grep -v "$dir/$dir"); do
I get

Code: [Select]
ls: Goldfrap/*.mp3: No such file or directory
using "$dir/"*".mp3" brings back the first space problem  

Thanks
« Last Edit: May 14, 2006, 06:43:50 pm by samot »
sl-5500 | WCF12 | SD kingstone 1gb | CF Memorex (Samsung) 64mb | OZ/OPIE (for the moment)

grog

  • Hero Member
  • *****
  • Posts: 692
    • View Profile
    • http://
Mediaplayer Playlist Maker Script
« Reply #13 on: May 16, 2006, 06:59:50 am »
Sorry for the delay. Even the midnight scipter has to 'service' his alter egos (husband, father, employee, pet owner, ... )

Quote
Quote
Code: [Select]
for file in (ls -1 $dir/*.mp3 | grep -v "$dir/$dir"); dokeephavingfun!
[div align=\"right\"][a href=\"index.php?act=findpost&pid=127035\"][{POST_SNAPBACK}][/a][/div]

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)

Quote
If I write

Code: [Select]
for file in "$(ls -1 $dir/*.mp3 | grep -v "$dir/$dir")"; do
I get

Code: [Select]
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: [Select]
for file in $(ls -1 "$dir/*.mp3" | grep -v "$dir/$dir"); do
I get

Code: [Select]
ls: Goldfrap/*.mp3: No such file or directory
using "$dir/"*".mp3" brings back the first space problem   

Thanks [div align=\"right\"][a href=\"index.php?act=findpost&pid=127037\"][{POST_SNAPBACK}][/a][/div]
Not sure what's going on there, so we'll avoid that & go in the back door

Code: [Select]
#!/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
enjoy
GROG!