Wednesday, September 1, 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.

Sunday, August 29, 2010

Philips GoGear Mix MP3 Player

My first MP3 player, purchased back in 2006, was in in-car FM modulator that could play MP3 files from a USB drive. It introduced me to the luxury of listening to podcasts on my daily commute, a habit which I continue to this day. However, it did have the problem of not being able to save the position in the podcast where it was stopped. This lead me to chop my podcasts into commute-sized chunks, which I did for a few months.

In mid-2007 I moved on to a "real" MP3 player, an LG UP3#. With a colour OLED screen and the ability to remember track positioning this was a great leap forward. However, after daily use for three years its battery has decreased markedly, requiring weekly top-ups. This led me to my latest purchase, a Philips GoGear Mix 4GB, for under $50. It's a bit bigger than the LG, but has a larger, more informative, screen. Like the LG it has a retractable USB plug, meaning that it can be plugged directly into a USB socket without a cable.

The GoGear has one major flaw, forgetfulness. If turned off while playing then it will resume from where it left off. However, if turned off when paused it will only remember the track, but not where within the track it was. Worse, when it is plugged into a computer, for recharging of batteries or replenishment of podcasts, it completely forgets what it was doing previously. When you have over 100 podcasts, some up to 2 hours long, it is downright inconvenient to have to find your place again. The sluggish fast-forwarding and rewinding doesn't help, but they shouldn't be necessary.

I have been in contact with Philips about this oversight. After some discussion they agreed to take my request to their firmware team. Whether this results in any improvement remains to be seen, but I am optimistic. As they noted, I can return the GoGear within twelve months for a full refund, but I'll stick it out, because otherwise it is a quite satisfactory device.

Wednesday, August 11, 2010

USB mouse erratic after resuming from sleep in Windows 7

Since I installed Windows 7 shortly after its release I have been having intermittent problems with my old Microsoft Intellimouse Explorer 3. Occasionally after the PC resumed from sleep mode the mouse pointer would move very slowly. My temporary fix was to unplug and replug the mouse into the USB port, which would fix the problem. Sending the PC to sleep and resuming again would also sometimes cure it.

I had hoped that I would magically find the problem fixed when I built a new PC last week. However, the problem remained, leading me to think it was caused by the combination of my mouse and Windows 7, as it hadn't been a problem for many years in Windows XP. A bit of Googling found other people with the same problem - Mouse stops responding when pc resumes from sleep. However, their solutions did not work for me.

My next step was to look for a software equivalent of the pulling out and inserting of the USB plug. I found this in the Device Manager. Go through all the USB Root Hubs, checking the Power tab in each to the one containing my USB device. At this stage the Advanced | Reset Hub button does not fix it. However, Driver | Disable then Enable does fix it. This means a workaround could be to write a script that does this action, triggered by the PC resuming. There is a trigger option in the Task Scheduler.

Googling further, I found a Microsoft page, A USB device may no longer work correctly after Windows Vista resumes from sleep or from hibernation, describing a change made in Windows Vista to how USB devices were treated after resuming. In summary, instead of devices being forcibly reset they are pleasantly asked to resume. Older, or perhaps defective devices, might not cope with this, so Microsoft include a hub by hub method of setting this back to the old method using a registry edit, by adding the ForceHCResetOnResume registry value for the relevant USB host controller. I made this change a couple of days ago, and it seems to have cured the problem.

Update: a few days later

The problem was not cured by the registry change, so I had a go at scripting the Reset Hub option in the Device Manager. However, this proved excessively tricky, even before I got to the hurdle of escalating privileges to administrator. My WSH script would open the device manager using "mmc devmgmt.msc", but I couldn't then activate that window to pass keypresses to.

I then learnt about devcon.exe, a Microsoft command-line alternative to the Device Manager. The previously linked version of devcon does not work in Windows 7. Instead we need to grab it from the 650MB Windows Driver Kit. Luckily you don't need to install the whole thing, but can extract just the small file we need. I used IZArc to extract \WDK\setuptools_x64fre.msi from the ISO, then Univeral Extractor to get devcon.exe from the MSI.

To run devcon.exe you need to run a command prompt as administrator. Then something like devcon.exe find * will list all devices, and I found the relevant USB hub by comparing with the values in the GUI Device Manager.

The necessary command was then devcon.exe restart "@USB\ROOT_HUB\4&2E16C4AF&0"

The final step was to get this command to run automatically when my PC resumed from standby. The relevant trigger in the Task Scheduler was Log: System; Source: Power-TroubleShooter; Event ID: 1. This task was set to "Run with the highest privileges".

I guess this post should have been called "How to reset a USB hub automatically upon resume from sleep in Windows 7".

In hindsight, a new mouse might have been a more straightforward option!

Friday, July 16, 2010

Holden's year in numbers

On a positive note, General Motors Holden have sold more cars than they've recalled this year...just (via Sydney Morning Herald)

Sunday, July 11, 2010

Farewell RealToMp3

After four years of good service it is time to retire my RealToMp3 audio downloading script. With the BBC's switch from RealMedia to Windows Media (WMA) streams it has become excessively laborious to set up individual streams to collect. As such, I have switched to Nerd of the Herd's Radio Downloader for all my podcast and stream downloading needs.

The Radio Downloader is a Windows-only graphical wrapper for various open source tools (the same tools as my script used). It's very much geared towards the novice user, but the options it lacks don't affect its usefulness. Upon installation it will run upon startup, and stay resident thereafter. There is not an option to stop it from running at startup. Ideally, I'd like a command-line option for it to run once, collect whatever audio is then available, then exit. There is a command-line option to make it exit, so I have a scheduled task that runs half an hour after login to stop the Radio Downloader, which gives it enough time to do its business, and then leaves my struggling old PC free to do other tasks.

Tuesday, June 1, 2010

Fixing a stuck OSD

MY five-year-old 19 inch Philips 190B6CB LCD monitor provided trusty service until yesterday, when the increase volume button decided to activate of its own accord, and stay on. As I don't use the monitor speakers this wouldn't be a big problem, except that it permanently activated the on-screen display, a fully opaque rectangle in the middle of the screen. I don't think my monitor has transparency options for the OSD, but the overriding nature of the volume meant I couldn't even get into the menu to move the OSD to a less conspicuous spot. Luckily, I have tools.

The monitor is a year or two outside its warranty period, and larger new monitors are really cheap, so I had no qualms about dissecting the screen. I read that some other soul had simply disconnected the front-panel controls to solve the problem in their monitor, so that was my aim. The bezel was mostly held in place by clips along its side, so with some rough flat-head screwdriver work, much like removing a bicycle inner tube, I got the bezel mostly off. There were also a couple of screws hidden under the stand attachment, but once they were removed the bezel came off easily.

The front-panel control section was a separate module that was easy to find and disconnect. The connection was a clip rather than being soldered, so the disconnection was easily reversible. A quick power-up confirmed that the problem was fixed.

The bezel went back on easily, and the monitor is now back in working order. One oddity is that the front-panel controls still work. Given that the problem is cured I'm not going to investigate further. I'll attribute it to the monitor fairy.

Saturday, May 22, 2010

Unfairness in the AFL draw

When you have 16 teams and 22 home and away rounds it is difficult to make the AFL draw fair for all teams. However, you might assume that the number of games played between certain pairs of teams would even out over multiple seasons. However, for reasons including minimising player travel and maximising crowd attendances this does not happen.

The chart below shows how many matches were scheduled from 1995 to 2010 between the two Western Australian teams, the West Coast Eagles and the Fremantle Dockers, compared to the Eagles versus the Brisbane Lions.



In sixteen years, the Eagles and Dockers played against each other 50% more often than the Eagles and Lions. If the Dockers were weak during that period and the Lions strong then that is a good outcome for the Eagles, but not for overall fairness in the competition. It's certainly a long enough period for all pairings to be scheduled evenly.