By Collin Allen

DVD Studio Pro Markers

March 24, 2005

Recently, I needed an easy way to get chapter markers into DVD Studio Pro without re-encoding my video with embedded markers, and I ran across an interesting tidbit of information. DVD Studio Pro has an “Import Marker List” command, but I wasn’t sure what kind of file it was expecting…another multimedia file with embedded markers? A CSV file? A proprietary format marker list? After much searching, I found this site which shows you exactly how to import a plain old tab-delimited file into your DVD Studio Pro track. Slick.

Update: Saved PDF version just in case the site goes away.

My Recent Tunes Code

March 23, 2005

Here is the code that I use to power my Recent Tunes list seen at right. It’s a little messy, but at least commented so you have some clue what each part is doing. The cover_update.php script is what does most of the work. You shouldn’t have to change anything in the amazon folder – that’s all there to talk to the API, which you will need access to. I also recommend Recent Tunes for updating your tracks from iTunes. Note that I use the current tune, not the list of recent tunes, as it makes managing the MySQL database easier and lessens the load put on Amazon’s API (which I imagine has a ~1000 query per day limit). If you have questions about using it, post a comment so that others can benefit from the conversation as well.

BitTorrent Info Scraping

March 21, 2005

After using TorrentSpy on Windows for a while, I wanted a Mac version to do some of the same functions. TorrentSpy’s main feature is that it allows you to see the current number of users on a .torrent file in real-time. I was curious how it worked, so with a little traffic capturing with Ethereal, I was able to see that TorrentSpy was contacting the tracker listed inside the .torrent file at a specific address that was similar to the actual web address of the tracker. This special address, I figured, must hand real-time data back to TorrentSpy. After a minute or two of wandering around on Google (have I mentioned yet how much I love Google?), I came up with the protocol to be followed for transforming torrent announce URLs into “scrape” URLs on a Yahoo groups post. With this information, I started doing some coding in PHP to see what I could come up with.

The next problem presented was that of decoding a .torrent file so the information could be pulled out of it. A great open source project called TorrentParse came to the rescue here, as it provides PHP code for encoding and decoding BitTorrent metainfo files. As I would find out a short while later, these libraries are also pivotal in decoding the real-time information retrieved from the tracker server.

The code I wrote has only a small few parts. The first handles the uploading of a torrent file and checks to make sure it is of the required file type. The next partdecodes the given .torrent file with TorrentParse and extracts the announce URL (the address that the BitTorrent client notifies to show the new seed on the tracker). I wrote a small function called makescrape() that transforms the announce URL into a scrape URL per Bram’s post, linked to above. Upon requesting this new scrape URL, you are returned a BitTorrent-encoded chunk of data containing the real-time information about the torrent. Run that through TorrentParse’s decode function, and pull out the data you want to display.

I would post a demo of the code, but I’m afraid it would be automated and/or abused. However you’re free to download the code and try it out. It still needs some work, especially in handling and managing uploads, but it all works well enough to display basic real-time torrent information. It’s not exactly the Mac version I had in mind from the start, but it could be adapted to a Mac OS X widget with a little work. Get the code here. Enjoy.


March 15, 2005

I recently discovered RCDefaultApp, a Mac OS X preference pane that gives you incredible control over some things that are hidden away in the system. For example, it lets you set the default application for handling URLs with different prefixes such as feed://, irc://, news://, etc. It also controls every file extension and type handled by Mac OS X, which is nice because sometimes the “Change All” button in Finder info windows doesn’t always do what it should. There are a few other things that you can use it for, like setting handlers for different MIME types and URLs. If you need very specific control over different file types, prefixes, extensions, and handler applications, this prefpane is exactly what you need. It, too, is freeware. I’m also impressed at how small its file size is - 98 KB. What’s not to love?

My Recent Tunes

March 15, 2005

A number of people have asked me how the Recent Tunes section of this site works. It’s a little complicated, but here’s how.

First, you need to get track info from iTunes to your website in a fairly timely basis to keep the information accurate. Freshly Squeezed Software, makers of the popular Mac newsreader PulpFiction, has a nice freeware application called Recent Tunes which does exactly that. It can upload a list of recent tracks as well as the current track, all formatted according to a template you design. I don’t use the recent tracks list, and you’ll see why very shortly.

With the current track info on the website, it’s time to actually do something with that data. You could stop here and simply include the HTML file in your design with a small PHP command, and the current tune info would show up, but with no artwork or links. The next step is to create a timed or invoke-able script that will open up that current track HTML file, split apart the various chunks of information (artist, album, title, etc.), and go from there. Now, I should mention at this point that the current track HTML file that Recent Tunes uploads does not have to be a fully formatted HTML file, by which I mean all the standard tags can be left out – it will make your life easier while writing the script that splits up the data.

In Recent Tunes, I set my template to show the album, artist, title, and rating, each separated with a simple few asterisks. This string of asterisks is what your code will look for when splitting up song info. Do note that if one of your current tracks has five asterisks in one of those four pieces of information, your script will break unless that possibility is accounted for. PHP has a wonderful and amusing function called explode(), which separates data however many times is necessary, given a string to split on. In this example, you would do list($artist, $album, $title, $rating) = explode("*****", $trackinfo); After that, you could do some error checking to make sure none of those fields are empty. If one or more is empty, it might not be worth your while to even bother continuing with the script, so have it exit cleanly now.

Now that you have the song info from your computer, to your website, read in with PHP, and split apart into usable bits, you are ready to start looking up artwork, links, and more. has a very nice web service interface that provides just about every bit of info they have on a product, including artwork. This is where the album images will come from. The only problem presented, aside from the task of writing the code that will be communicating with Amazon’s infrastructure, is that their artwork isn’t a consistent size. They offer “small”, “medium”, and “large”, but the sizes in each category vary slightly. If we’re going to go to the trouble of doing all this, it should look good. The obvious answer is to make the album artwork the size you want.

Since the “small” artwork is already low in detail, it would look even worse if resized – any manipulations you make will lessen the quality each time. The best way to approach this would be to use the biggest available image and scale it to the size you want in one shot. Enter GD, an open source image library capable of handling common image formats. PHP must be compiled to use GD, but it’s quite common. I’ve found that most web hosts provide it. It is not built into PHP that comes with Mac OS X, however it is available as an installer package from Marc Liyanage’s site. I always use his releases for local development and never have problems with them.

Once you retrieve the artwork from Amazon by matching artists and album titles, use GD to scale the image to 50x50 pixels and save it (just write it to a file with a unique name, say, an MD5 hash of the song info with “.jpg” tacked on). Amazon’s API also provides the product URL too, so hang onto that as well. The iTunes Music Store addresses are relatively easy to create. Using information I dug up on NSLog();, I was able to create a small function that returns an iTunes link. Once you’ve collected all this information and media, you’re ready to save it all to a database. MySQL runs WordPress, so it was only fitting that I use the same database only a different table. Do a MySQL “INSERT” command and log the song title, artist, album, rating, time (if you want), cover artwork path, Amazon product URL, and iTunes Music Store URL.

A good chunk of code to add here is one that will read the ID of the tenth newest row, and remove all rows and images that were before it. I found a good way to do it was read out the rows first, unlink the images using the paths set in the image path column, then MySQL “DELETE” that row, and continue until there are no more rows older than that tenth entry. In this way, you will keep your list of songs down and not gradually run yourself out of disk space by keeping ancient artwork files around.

Finally, when a visitor comes by, read out the last 5 or so rows (no more than your limit set in the previous paragraph) from the table and format them using some CSS. And last but not least – error checking everywhere. If artwork is not found or broken, or if the scaled image file doesn’t exist, or GD chokes on a corrupted Amazon image, simply don’t add that tune to the database and skip to the next one. It’s just a song.

I would release the code I wrote now, but it’s a little sloppy. I hacked it together in two days time, so I can’t guarantee anything! Let me know if you see any problems. If it continues to work well, I’ll surely hand it out.

Known Bugs: Albums with single quotes in any of the info cause the iTunes link to break. They are stored using the HTML entities ON for quotes, yet that seems to stop iTunes from understanding them. Not yet sure why that is.