LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Crappy MP3 player doesn't have a shuffle mode (https://www.linuxquestions.org/questions/programming-9/crappy-mp3-player-doesnt-have-a-shuffle-mode-437449/)

Phyrexicaid 04-21-2006 10:08 AM

Crappy MP3 player doesn't have a shuffle mode
 
Crappy MP3 player doesn't have a shuffle mode
So...

Should I try attempt to write a script that renames the files randomly so that I get a semi-random mode? (if so, I have no clue where to start)

OR

would a little java program be better/easier? Plus side here is that I could run it on windows and linux ;)

burntfuse 04-21-2006 12:59 PM

Java might be easier...

sw67 04-21-2006 01:40 PM

I'd say a bash script is simple enough.
This should do what you want:

Code:

#!/bin/bash
TT=$(ls | wc -l)
for i in *
do
        let "rn=$RANDOM % $TT"
        mv "$i" "$rn$i"
done

Put all your mp3s in a folder, save that script to something like random.sh (in the same directory as the mp3s), and run it.
Don't forget to do a chmod +x on the .sh file :)

What it'll do is loop through every file in the folder, and stick a random number in front of it, thereby effectively shuffling your playlist.

It does also rename itself, but that's something I can't be bothered to change right now ;)

I wouldn't recommend putting it in your home diectory or anything like that, since it will rename **everything** in the current folder.

Hope it's helpful...
Sam

Phyrexicaid 04-22-2006 01:13 AM

That is really helpful!

Thanks so much for posting that :D

Phyrexicaid 05-14-2006 11:24 AM

Hey,

I've done some modification to the original script. The random number in front works pretty well, but the player seems to have an interesting way of ordering the songs, so in order to give it less options I want to only have a number in front of .mp3, I then have a restore script that can regenerate all the file names. Only problem is that now I have the possibility of overwriting a file. How can I check to see that a file won't be overwritten? (My script writing abilities aren't the best) And... horror of horrors, anyone know how to convert this to a .bat file so that I can run this in windows and linux ;)
Code:

TT=$(ls *.mp3 | wc -l)
for i in *.mp3
do
        let "rn=$RANDOM % $TT * 2"
        let "rn2=$RANDOM % $TT"
        echo "mv \"$rn - $rn2.mp3\" \"$i\"" >> restore.sh
        mv "$i" "$rn - $rn2.mp3"
done
echo "rm restore.sh" >> restore.sh


Phyrexicaid 05-14-2006 12:35 PM

Could someone shed some light on this;
The way this mp3 player actually plays songs is beyond me. I have the following songs in order (this is from the restore script) but when I play the songs on the mp3 player, it starts with Breakerfall, and then plays all the songs in order after that (Evacuation, Fly Paper jet etc). Now they obviously don't follow sequencially looking at their names. And when I restore their original names it starts playing "A Perfect Circle". WTF is going on?!?

It plays according to a directory listing when I don't change anything. When I run the randomiser, it starts on some arb song but then starts playing in order again! Huh? How?

Code:

mv "AA - 29 - 87 - 18.mp3" "A Perfect Circle - Mer De Noms - 02 - Magdalena.mp3.mp3"
mv "AA - 69 - 51 - 9.mp3" "A Perfect Circle - Mer De Noms - 03 - Rose.mp3.mp3"
mv "AA - 2 - 14 - 68.mp3" "A Perfect Circle - Mer De Noms - 07 - Sleeping Beauty.mp3.mp3"
mv "AA - 21 - 70 - 88.mp3" "A Perfect Circle - Mer De Noms - 08 - Thomas.mp3.mp3"
mv "AA - 58 - 30 - 64.mp3" "A Perfect Circle - Mer De Noms - 10 - Thinking Of You.mp3.mp3"
mv "AA - 38 - 3 - 22.mp3" "A Perfect Circle - Mer De Noms - 11 - Brena.mp3.mp3"
mv "AA - 9 - 13 - 72.mp3" "Alice In Chains - 03 Rain When I Die.mp3.mp3"
mv "AA - 14 - 2 - 45.mp3" "Alice In Chains - 08 Dirt.mp3.mp3"
mv "AA - 16 - 42 - 55.mp3" "Alice In Chains - 13 Would.mp3.mp3"
mv "AA - 59 - 47 - 31.mp3" "Alice in Chains - 01 Grind.mp3.mp3"
mv "AA - 83 - 60 - 29.mp3" "Alice in Chains - 12 Angry Chair.mp3.mp3"
mv "AA - 85 - 41 - 80.mp3" "Alice in Chains - 12 Over Now.mp3.mp3"
mv "AA - 6 - 27 - 78.mp3" "Breakerfall.mp3.mp3"
mv "AA - 58 - 48 - 43.mp3" "Evacuation.mp3.mp3"
mv "AA - 41 - 1 - 57.mp3" "Fly Paper Jet Live - Festival Song.mp3.mp3"
mv "AA - 16 - 40 - 60.mp3" "Fly Paper Jet Live - The Light Fantastic.mp3.mp3"
mv "AA - 22 - 33 - 57.mp3" "God's dice.mp3.mp3"
mv "AA - 78 - 31 - 60.mp3" "Grievance.mp3.mp3"
mv "AA - 34 - 47 - 13.mp3" "Insignificance.mp3.mp3"
mv "AA - 73 - 1 - 45.mp3" "Light years.mp3.mp3"
mv "AA - 15 - 69 - 16.mp3" "Limp Bizkit - 02 - eat you alive.mp3.mp3"
mv "AA - 44 - 65 - 41.mp3" "Limp Bizkit - 15 - behind blue eyes.mp3.mp3"
mv "AA - 19 - 55 - 53.mp3" "Limp Bizkit - 16 - drown.mp3.mp3"


Phyrexicaid 05-16-2006 11:16 AM

Hmmmmmm.

Okay, so I used id3 -d to delete the id3 tags from the files. Turns out (obviously) that the mp3 player was reading id3 tags after reading the first random song number. Now how to remove the id3 tags but be able to restore them like I can with the restore script?


All times are GMT -5. The time now is 02:51 PM.