Python script to randomise an m3u playlist

While I’m blogging scripts for playlist manipulation here is one I use in a nightly cron job to shuffle our playlists so that various devices playing from them have some daily variety. All disclaimers apply, it’s rough and ready but WorksForMe (TM).

I have an entry in my crontab like this

which takes a static playlist and produces a nightly shuffled version.

Python script to add a file to a playlist

I have a number of playlists on Gondolin, which is a headless machine. I wanted to be able to easily add a given mp3 file to the playlists which are in m3u format. That means that each entry has both the filename and an extended line with some basic metadata, in particular the track length in seconds, the track artist and name. I wanted a script that could extract this information from the mp3 file and make adding the entry easy. So I wrote this in Python. It’s rough and ready and it is probably not very Pythonic but it’s working for me. The script should create a playlist if it doesn’t currently exist, and check for a newline at the end of the file so that the appended lines are really on a new line. ItWorksForMe (TM).

This uses the eyeD3 Python library, which on Debian is provided in python-eyed3.

My basic usage is

the last parameter is the path relative to which the mp3 filename should be written to. This is useful for me because I rsync the whole tree between machines, as you will see there are options for writing an absolute pathname if you prefer. I should probably rewrite the script to do it relative to the playlist, but that’s another day.

Extending a wired doorbell with a wireless one

We moved into our new house in January 2013. There was, and still is, plenty of remedial work to do in the house, but by the end of 2013 we had renovated the main reception room that we “live” in. This is the middle floor (it’s a three floor property) and immediately above the wired, AC doorbell in the hall downstairs. The thing is, when we get into that room and close the door to stop any noise disturbing Matilda, you can’t hear the doorbell below at all. It’s largely easy to hear from other parts of the house. I didn’t want to replace the good working doorbell, especially since in my experience outdoor switches last longest when there is AC current going through them.

So I began researching doorbell extenders but found they were quite pricey and typically required batteries. I did find what looked like a suitable system for US voltages and sockets but nothing for the UK. So I bagan to wonder if I could just rig something up from a cheap wireless doorbell to have an additional sounder. Basically to wire the voltage from the existing wired door bell to a switch of a wireless one. Because I usually search for solutions on the Oracle of Google before such undertakings, and didn’t find anything quite like I wanted, I’m adding this to the mix.

My first problem was trying to convert the 12V AC I had metered in the bell box to something appropriate in DC. I looked at the components to build my own circuit for this, but remarkably discovered I could buy something from eBay from China for £1.60 (including postage) that performed the AC to DC conversion with a pot to allow the voltage to be calibrated. I will leave you to search for your own.

The AC to DC Converter
The AC to DC Converter

I then bought a pretty cheap wireless bell from Amazon. It cost £12.40 for a bell that would plug directly into the mains (so no battery), so this Kingavon wireless door bell did the job.

Wireless Bell
The Kingavon wireless bell. Nice and cheap, reasonable feature set.

The bell push normally takes a 3 V battery. My plan was to supply that voltage directly from the AC to DC converter to avoid the need for a battery at that end too. If I could rig up the 12 V AC that was produced in the wired bell box when the push was pressed this might work. So I took the bell and push into work and finally in a free 30 minutes grabbed two colleages and headed to the lab.

We connected the AC to DC converter to 12 V AC (as it would be in the bell box) and calibrated the pot until we had a 3 V DC output.

The micro-switch in the doorbell push was soldered closed (so that in effect the button was always pressed down). Finally the DC output was soldered to the battery pins on the door push.

Soldered Push Button
Note the short circuit across the micro switch (just to its left).

In bench tests we then tried turning on the supply to see how quickly the wireless doorbell push came up and activated the bell. As I suspected if the power was “jabbed” on there wasn’t enough time for the transmitted circuitry to get its act together, but when “pressed” for say just under a second (simulated by supplying the AC) the wireess bell went off. I figured this was the downside of going to a battery-less solution, but given that I had guests trying to ring the bell repeatedly (since they knew I was in) I figured this would work.

So I used a multi-meter to work out which terminals in the bell box went to 12 V when the bell push was pressed, hooked up the leads into the AC to DC converter and bingo, the set-up works. At the time of writing I still consider it to be in testing so the components are literally wrapped around the bell box, but since the box doesn’t contain batteries, there will be room to place them in later, once i get them properly insulated – and I get a new glue stick for my glue gun to fasten them in.

(Almost) final wiring
Wired up inside the box, but still trailing during extended testing.

So this approach works, but it won’t be for everyone – the wireless bell can fail to go off if someone really jabs the outdoor bell push, but for us, it’s a workable solution for £14 and the cost of some wire.