# Wednesday, June 23, 2010

A feature that I used to like in Windows Media Player 11 that was dropped in version 12 was the 'Recently Added' view. There is a way to produce an automatic playlist that includes recently added items, but it occurred to me that I use a variety of media players depending on my current whim (sometimes it'll even be a command line instance of mplayer through cygwin) and wouldn't it be great to have an auto-generated 'Recently Added' playlist in a format that any respectable media player would understand - namely M3U.

And besides, I wanted to play around with Powershell.

So, I put together the following Powershell script; something that stumped me for a while was to do with resolving absolute paths to relative paths; my issue was:

resolve-path -relative "E:\Music\Autechre\Quaristice\01 Altibzz.mp3"

would return

.\Autechre\Quaristice\01 Altibzz.mp3

but

resolve-path -relative "E:\Music\Peter Gabriel\Hit Disc 2\14 Downside Up [Live].mp3"

would return absolutely nothing. After returning to the script a few hours later, I realised that the issue was to do with wildcard expansion - Powershell uses '[...]' to match ranges or specified characters (see 'help wildcards' in Powershell). A quick flick through the help pages for resolve-path revealed a '-literalpath' parameter, which means that no wildcard expansion is performed. The following command therefore:

resolve-path -relative -literalpath "E:\Music\Peter Gabriel\Hit Disc 2\14 Downside Up [Live].mp3"

gives

.\Peter Gabriel\Hit Disc 2\14 Downside Up [Live].mp3

as expected.

Just to round things off, I decided to emit extended M3U directives for applications that understand them. I stole the GetMP3MetaData function from Johan Straarup's blog entry which uses an interesting trick by instantiating a Shell.Application COM object and accessing the properties that it exposes on a selected file. From this information I could write out the relevant tag information from the selected files and calculate the length of the file in seconds.

From the Powershell command line, you can run the script as

.\Recently-Added.ps1 | Set-Content "Recently Added.m3u"

By default, it will produce a playlist of MP3 files that were created within the last 14 days; this can be adjusted by specifying the '-Days' parameter. For example, to create a list containing files created within the last 21 days:

.\Recently-Added.ps1 -Days 21

I hope someone finds this useful someday.

#
# Recently-Added.ps1
#
param([int]$Days = 14)
$objShell = New-Object -ComObject Shell.Application

function GetMP3MetaData($path)
{
    $file = split-path $path -leaf
    $path = split-path $path
    $objFolder = $objShell.namespace($path)
    $objFile = $objFolder.parsename($file)
    $result = @{}
    0..266 | % {
        if ($objFolder.getDetailsOf($objFile, $_)) {
            $result[$($objFolder.getDetailsOf($objFolder.items, $_))] = $objFolder.getDetailsOf($objFile, $_)
        }
    }
    return $result
}

"#EXTM3U"
gci -recurse -include *.mp3 | `
    ? { $_.CreationTime -gt (get-date).AddDays($Days * -1) } | `
    % {
        $path = resolve-path -relative -literalpath $_.FullName
        $info = GetMP3MetaData($_)
        $duration = [timespan]$info.Duration
        "#EXTINF:{0},{1} - {2}" -f $duration.TotalSeconds, $info.Artist, $info.Title
        $path
    }

 

posted on Wednesday, June 23, 2010 11:15:05 AM UTC  #    Comments [0] Trackback
# Wednesday, August 05, 2009

One of the highlights of going to visit my Amma as a small boy used to be reading the old hardback copy of "Struwwelpeter: Merry Tales and Funny Pictures" by Heinrich Hoffman – although it was the inspiration for several recurring nightmares, there was something grotesquely compelling about the book that meant I couldn’t stop re-reading it. The idea that any of the stories could have been described as "Merry Tales" or that this could in any way be considered a children's book was (and still is) bizarre.

My favourite story was always "The Story Of Little Suck-a-Thumb"; it’s the completely cold and matter of fact way in which the unfortunate boy’s mother reacts to her son's mutilation at the hands of the tailor and the freakish illustration of the "great, long, red-legged scissor-man" himself leaping in through the open door with his enormous shears that completely captivated me then (and now).

The Story of Little Suck-a-Thumb

The Story of Little Suck-A-Thumb

One day Mamma said "Conrad dear,
I must go out and leave you here.
But mind now, Conrad, what I say,
Don't suck your thumb while I'm away.
The great tall tailor always comes
To little boys who suck their thumbs;
And ere they dream what he's about,
He takes his great sharp scissors out,
And cuts their thumbs clean off—and then,
You know, they never grow again."
Mamma had scarcely turned her back,
The thumb was in, Alack! Alack!

The great, long, red-legged scissor-man.

The door flew open, in he ran,
The great, long, red-legged scissor-man.
Oh! children, see! the tailor's come
And caught out little Suck-a-Thumb.
Snip! Snap! Snip! the scissors go;
And Conrad cries out "Oh! Oh! Oh!"
Snip! Snap! Snip! They go so fast,
That both his thumbs are off at last.

 
Mamma comes home, there Conrad stands

Mamma comes home: there Conrad stands,
And looks quite sad, and shows his hands;
"Ah!" said Mamma, "I knew he'd come
To naughty little Suck-a-Thumb."

The complete nightmare can be downloaded from Project Gutenberg

posted on Wednesday, August 05, 2009 9:25:32 AM UTC  #    Comments [1] Trackback
# Thursday, July 23, 2009

The hinge on India’s pink DS lite broke the other day, which left the top screen hanging on precariously for dear life, so rather than risk the wrath of an eight year old if the thing did give out I got a replacement case. I opted for a nice purple colour and armed with a trusty triwing screwdriver, miniature screwdriver set and a couple of young helpers I replaced the case.

I opted to keep the original pink DS’s buttons, D-pad and screen decals – I think the end result is quite fetching.

Pink n' Purple DS

posted on Thursday, July 23, 2009 5:22:38 PM UTC  #    Comments [0] Trackback
# Friday, July 17, 2009

Just stumbled across this cartoon via B3ta; it makes the case that Aldous Huxley was the more prophetic author compared to George Orwell, contrasting Brave New World against 1984. It’s true that Orwell may have enriched the English language more than Huxley (Newspeak, Big Brother, Room 101, Doublethink etc.), but Huxley may well have had the more accurate vision.

http://fatpita.net/?i=1952

posted on Friday, July 17, 2009 7:06:31 PM UTC  #    Comments [0] Trackback
# Thursday, June 18, 2009
The gig tonight at The Old Ship in Dorcester is not happening – cock up with booking confirmations!
posted on Thursday, June 18, 2009 12:37:04 PM UTC  #    Comments [0] Trackback