Archive for the ‘Perl Scripts’ Category

i2aCleaner—Perl Script to Remove Unused Music from Android microSD Card

Wednesday, January 6th, 2010

One problem with using the itunes2android Perl script to create playlists and populate your Android microSD card for use with the Just Playlists app is that it’s a bit hard to remove music selectively in the future.  For instance, if you have several playlists that you created using itunes2android and then decide you’d like to remove one of the playlists and the music that it references, you’d have to go through the music directory and delete the directories and music files manually.  Even worse, if you delete music that is still referenced in another playlist, that playlist won’t be able to find it.

I wrote the i2aCleaner script to get around this problem.  If you want to remove the music associated with a playlist, just delete the playlist out of your \Music\Playlists directory on your microSD card and then, while it’s mounted under Windows, run i2aCleaner.  This script looks at all your playlist files and removes any music from under the music directory created by itunes2android that isn’t referenced in any playlist.  In my case and in the example I used when describing itunes2android, this is the D:\Music\ipod directory when your microSD card is mounted.  Again referring to the original example and assuming you put the i2aCleaner script in C:\scripts on your computer, the command line to do this would be

perl c:\scripts\ d ipod

where “d” is the drive letter of your mounted phone or microSD card and “ipod” is the name of the directory where your music is stored under \Music on the microSD card.

The script will get rid of all unused music and directories.  It won’t affect anything else in your D:\Music directory.

Remember that this script will only work right if you use the itunes2android script to manage your playlists.  And if you have music that you moved over to the microSD card in some other way, it shouldn’t be kept under the \Music\ipod directory, since it will get deleted by i2aCleaner if not referenced by the playlist files.

You can download a ZIP archive with the i2aCleaner script here.

itunes2android—Perl Script for Moving Music from iTunes to an Android microSD Card

Sunday, December 27th, 2009

To use the Just Playlists program on an Android phone, you need to create M3U playlists and move them and your music to your phone’s microSD card.  If you use iTunes to manage your music library on your computer—as I do—one way to accomplish this is to use the iTunes playlists as the starting point.  The Perl script I created called itunes2android does just this.  You can download it here.

The script is meant to be run under Microsoft Windows—though adapting it to the Mac or Linux wouldn’t be difficult.  Here are the steps for using it:

  • Download the script and save it to a folder on your computer—let’s call it C:\scripts as an example.  It’s in a ZIP archive, so be sure to unzip it.
  • Install a Perl interpreter on your computer.  The one I use is called Strawberry Perl and can be found here.  ActiveState makes another Perl distribution for Windows.  It should work with it, as well, though I haven’t tried it.
  • Use iTunes to create a playlist of some of your music.  Once this is done, right-click on the playlist name.  One of the choices in the menu is “Export…”.  Choose this, and choose to export it as a text file into a folder of your choice.  Let’s use C:\playlists as an example directory and favorites.txt as the playlist export file name.
  • Now, open a DOS command prompt and change directory to where you put the exported playlist.  Using my example directory, the command would be

cd c:\playlists

  • Connect your Android phone to your computer with its USB cable.  Once connected, pull down the notification bar on the phone and choose to mount your microSD card.
  • Open up “My Computer” on your computer and note the drive letter assigned to your phone.  Let’s assume it’s D:
  • Go back to your DOS command prompt window and use the itunes2android script.  Using my example set-up, the command would be

perl c:\scripts\ favorites.txt d

  • The script will run and tell you what it’s doing.  When it’s done, you can open up the microSD card on your computer and look around for the new files it copied over.  When you’re done, unmount your phone and you’ll be ready to go.

The script will create a directory tree on your microSD card of D:\Music\ipod\… for your music tracks, based on the structure you’ve used to store them on your computer.  The “ipod” directory isn’t special but just happens to be the way I do it, to keep music moved over by itunes2android separate from any other files in the “Music” folder.   The “Music” folder is probably already on your microSD card, since it’s where Android puts music by default.  There will also be a D:\Music\Playlists folder that will contain the file favorites.m3u.  This is the playlist that you can use with Just Playlists.

A few more details.  First, I choose to manage my music files manually and thus they aren’t stored in the default iTunes directory structure.  I store my music as C:\ipod\<Artist>\<Album>\<track>.  If you let iTunes decide where to keep your music, the above should still work, but I don’t know exactly what directory structure you’ll end up with on your microSD card.  Feel free to comment here and let me know what you get or if it gives you problems.  Also, I live in the USA and have all my data on a Windows computer using character sets for English.  My script might have problems if you are using character sets for other languages.

If you use iTunes to add album art to your music, it doesn’t actually put the artwork in each music file.  I manually tell iTunes to write the artwork to each music file.  This way, other music players like Just Playlists and the default Android music player can find the artwork.  I’d be glad to post on how to do this in the future, if anyone is interested.

Finally, you can use the M3U playlists you create in the default music player on your Android phone.  They will show up in the “Playlists” list, once Android gets around to re-scanning your microSD card.  Your music will also show up under the other play categories in the default music player.  I should make the disclaimer that this is true with a Google Experience phone like the G1.  I’d guess it should also be true for the music players on phones like the Hero and Droid, but I haven’t used them to be sure.