Jump to content

quick and dirty file name randomizer and derandomizer?


Fblade1987
 Share

Recommended Posts

Hey guys,

I recently bought myself a cheap knock-off ipod shuffle, so it for a £2 and couldnt resist :P , however I've noticed it doesnt actually shuffle the songs it just plays albums/folders through and then onto the next.

This got me thinking I could simulate a the shuffle experience by somehow randomizing the file names and moving all the files to the root of the mp3 player, but so that i would be able to reconize what songs are what when looking at them on a computer have something that will de-randomize the files back to their orignal state. Is there an script that could do this? or if not can anyone recommend a good language i could use that will work on all OS'S? and also could someone help me knock a quick and dirty one togther?

Thanks matt

Link to comment
Share on other sites

A Python or Perl script would work on any OS, provided that you install the interpreter. Basic C/C++ should compile without change, but of course the binary produced is platform-specific. Compiled Java programs are supposed to work on all platforms.

In this case I think a script will be the easiest and fastest to do. I suggest adding a random 4-digit number at the beginning of each filename. Makes it easy to de-randomize.

Link to comment
Share on other sites

Well I was extra bored :rolleyes: So I made a python script to help you do this, Make sure you run it in the directory with all your songs.

You can download python here http://www.python.org/download/releases/2.5.4/

Once it has generated the random names, copy the folder of songs to your Ipod. Then you can hit enter and the script will change the songs back to their original state.

[Tested on Ubuntu GNU/Linux, should work with windows tho.]

#Run this in the directory with your songs, and DO NOT CLOSE this until you have recovered the names.
raw_input("Are you sure you want to continue? Make sure not to exit prematurely.")
import os,random
chars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
old_new = {}
for song in os.listdir('.'):
    if song.endswith((".mp3",".wav",".aac")) == True:
        new = str(random.randint(0,2000))+random.choice(chars)+song[-4:]
        old_new[new] = song
        os.rename(song,new)
        print "Generated random name"
    else:
        print "Unrecognized extension"
        
def recover():
    for old_song in os.listdir('.'):
        try:
            os.rename(old_song,old_new[old_song])
            "Song name recovered...."
        except KeyError:
            pass
         
raw_input("\nHave you copied the songs to your Ipod?")
raw_input("Hit enter to recover the names")
recover()

It's a bit overkill :P but I love overkill D:

Link to comment
Share on other sites

Well I was extra bored :rolleyes: So I made a python script to help you do this, Make sure you run it in the directory with all your songs.

You can download python here http://www.python.org/download/releases/2.5.4/

Once it has generated the random names, copy the folder of songs to your Ipod. Then you can hit enter and the script will change the songs back to their original state.

[Tested on Ubuntu GNU/Linux, should work with windows tho.]

#Run this in the directory with your songs, and DO NOT CLOSE this until you have recovered the names.
raw_input("Are you sure you want to continue? Make sure not to exit prematurely.")
import os,random,time
chars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
....
.....

It's a bit overkill :P but I love overkill D:

instead of writing chars = ["a","b",.....]

you could say chars = list("abcdefghijklmnopqrstuvwxyz") it may save you some time

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...