Nav links

Wednesday, 1 September 2010

Introducing podShuffle

Intelligent automatic ordering of podcasts - podShuffle.py

Requires: Python 2.x and an mp3 player which plays tracks in alphabetical order
Optional: Mutagen (Python module for reading mp3 tags)

Features
  • chronological ordering of episodes from each feed (oldest first)
  • random ordering of feeds
  • minimal clumping of episodes from a single feed
  • free (GPL2 licence)

Example of usage: podShuffle.py f:\music

Other options

podShuffle.py [options] folder

-h or --helpshows a brief summary of options
-c CHARSnumber of characters at the start of each filename to compare if album name is not being used (if file is not an mp3 or mutagen is not installed). The default is 5.
-p PREFIXformat of the prefix added to filenames to order them. It must include #. The default {#} produces files such as {001}filename.mp3
-r or --revertrevert filenames to unshuffled format (removes their prefixes)
-e or --evenevenly-space podcasts. If you have one feed with many more podcasts than any other then it will clump somewhere. By default podShuffle will spread it out throughout the playlist, making it occur more often than a fair ordering would give. The '-e' option forces an even ordering, at the expense of clumping at the end.

Background

After the purchase of my new MP3 player I was motivated to write a sorting program for my podcasts that required no manual intervention. I've previously used Reorganize!, but the manual ordering process is a bit tedious, and its shuffle feature requires too much manual tinkering post-shuffle for my tastes.

podShuffle's reordering is performed by renaming files such that their alphabetical order is as desired. (Some MP3 players use FAT ordering, which is tricky to modify from Python. If yours is not playing in alphabetical order then it may be by FAT, which is basically the order in which the file were copied onto the player.)

I wrote the script to run in Python 2 and 3. However, it works much better when used with the Mutagen library, which is only available for Python 2. Mutagen enables the fetching of album names from mp3 files, which for podcasts indicates their feed. Without Mutagen the script uses the much less reliable mechanism of comparing the first n (5 by default) characters of each filename. Other libraries I considered included eyeD3 and TagPy, but neither was straightforward to install in Windows.

Aside from the chronological ordering of podcasts from each source, the actual ordering of "pod groups" is random, so you can re-run the script any number of times to get different results.