Recently in Programming Category

Feb
09
itunes-logo.png

iTunes automatically creates a backup copy of its library file in a XML format. Manually creating this file from the File->Library menu is also possible. By doing so, the entire iTunes Library metadata is exported to an XML format where it can be further processed. Common requirements may be to import the library into an Excel spreadsheet as a comma-separated-value (CSV) file, or to insert the metadata into a database using SQL statements.

For me, I was working on a audio/video related project and I needed some sample, yet real-life metadata to work with. So I ended up writing a simple and compressive iTunes parsing library, implemented as a single XSL that performs most of the work. This proved to be especially useful since Apple did not implement the iTunes Library as a 'real' schema, but rather a freeform key/value pair whose definition isn't published anywhere.

The iTunes Stylesheet XSL is freely available under a BSD license. Using it can greatly reduce the amount of effort required to parse and use iTunes Library metadata. The library has been developed and tested against iTunes version 9.

Now on to the code... The following example shows how easy it is to iterate through every title and output the name and artist.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
<xsl:include href="iTunes.xsl">
    
<xsl:template match="/">
    <xsl:for-each select="plist/dict/dict/dict">

        <xsl:call-template name="name">,
        <xsl:call-template name="artist">

    </xsl:for-each>
</xsl:call-template>

Now suppose the requirement was to insert the library into a SQL database; no problem. The iTunes Stylesheet XSL has a built-in template for escaping when the output is SQL, specifically, it escapes singles quotes.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
<xsl:include href="iTunes.xsl">
    
<xsl:template match="/">
    <xsl:for-each select="plist/dict/dict/dict"> 

        <xsl:call-template name="sql_escape">
            <xsl:with-param name="arg1">
                <xsl:call-template name="name">
            </xsl:call-template>
        </xsl:with-param>,

        <xsl:call-template name="sql_escape">
            <xsl:with-param name="arg1">
                <xsl:call-template name="artist">
            </xsl:call-template>
        </xsl:with-param>

    </xsl:for-each>
</xsl:call-template>

Download iTunes Stylesheet XSL

iTunes Stylesheet XSL contains templates to parse the following:

  • Track ID
  • Name
  • Artist
  • Composer
  • Album Artist
  • Album
  • Genre
  • Kind
  • Size
  • Total Time
  • Disc Number
  • Disc Count
  • Track Number
  • Track Count
  • Year
  • Date Modified
  • Date Added
  • Bit Rate
  • Sample Rate
  • Comments
  • Play Count
  • Play Date
  • Play Date UTC
  • Release Date
  • Artwork Count
  • Rating
  • Rating Computed
  • Album Rating
  • Series
  • Season
  • Episode
  • Episode Order
  • Content Rating
  • Persistent ID
  • Track Type
  • Purchased
  • Podcast
  • Unplayed
  • Has Video
  • HD
  • Movie
  • TV Show
  • Music Video
  • Video Width
  • Video Height
  • Location
  • File Folder Count
  • Library Folder Count

Download iTunes Stylesheet XSL

Nov
12
Merge Sign #2The ability to find differences in source code files and merge conflicts if they arise is a basic task that every programmer requires. Utilities that perform this task are part of every programmers arsenal. So it came as quite a surprise that the selection for such tools on the Mac (a fantastic development platform) was extremely limited.

For my particular purposes, I need a graphical diff/merge tool that's free, works on both the local file system and Subversion, has a way to quickly see how many differences exist and rapidly go to each one. Plus it's going to be running on a Mac, so it needs to have a decent user interface. That's not too much to ask for, is it?

In this post, I'll take a brief look at three free apps, FileMerge, Meld, and Perforce P4Merge. This is not meant to be a comprehensive review, but rather an overview of some of the most popular and capable diff/merge tools available.


FileMerge

Screenshot: FileMergeFilemerge.app, included with XCode, provides basic diff/merge capabilities. As a product from Apple, I would have expected the interface and the representation of changes to be the best-in-class. This however could not be further from the truth. Filemerge is downright painful to look at, and pretty useless. In order to view each change (next/previous), you need to go two menu levels deep in order to get to the command. And if you forget the keyboard shortcut, you have to do it all over again. The number of differences are  located at the bottom of the app. This would be acceptable if I was working with the finder, but I'm working with FileMerge. The most important thing it can tell me is how many changes there are, and it's at the bottom.


Meld

Screenshot: Meld on LinuxMeld is an open source visual diff/merge tool available for Linux and all the Unixes, including Mac OS X. I use Meld daily on Ubuntu and it's solid, provides good merge capabilities, and meets most of my requirements, including being able to quickly go to the next/previous difference in a file. But like FileMerge, the number of differences isn't displayed where I would like it to be. Using Meld on a Mac isn't as Mac-like as other clients. It requires libraries typically only found on Linux/Unix so there's a lot of prerequesites to install first, including X and gnome. Fortunately several articles exist on how to do this, including this one for installing Meld using MacPorts.


Perforce P4Merge

Screenshot: Perforce P4MergePerforce is a highly flexible yet slightly obscure SCM. The concepts of clientspecs are fascinating, especially for inherently limited filesystems like Fat and NTFS, yet I'm still baffled why Workspaces are stored on the server and are user/machine specific. However, included in the free Perforce client (p4v) is a little gem called P4Merge.  Available for Windows, Linux and Mac, P4Merge is one of the best free diff and merge clients I have ever worked with, and best of all, it works completely independently of Perforce. In other words, P4Merge can be used to diff/merge files from virtually any version control system, including git and Subversion. It is also the most usable of the clients, providing a minimal toolbar with quick access to previous/next changes and the number of differences in the files. The merge capabilities are also very impressive.

P4Merge integrates with the Mac quite well, including integration with Cornerstone Subversion client. Using Cornerstone, you can change the diff tool to P4Merge. There is a trick however. Simply specifying P4Merge as the application is not enough. You actually need to perform this task twice, the second time will actually drill into the contents of the app. Specifically, you need to set the app to: /Applications/p4merge/Contents/Resources/launchp4merge. Once this is done, You'll be able to quickly diff files in Cornerstone using one of the best free diff/merge viewers available.


Honorable Mentions

The following tools did not meet my requirements. Most were paid apps, the most expensive of which was Araxis Merge, which is an absolutely fantastic tool by the way.

DiffFiles is a standalone, commercial client included in oXygen XML. I use oXygen XML on the Mac all the time, as it provides the closest thing to XMLSpy on Windows. The bundle also includes a Subversion client, DiffDirs, Tree Editor, and XML Generator, so it's quite a good deal.

Changes by Connect Flow is a commercial, Mac only viewer.

DiffMerge from SourceGear is a free, cross-platform viewer. It appears to have the features a developer would want, but it's ugly as sin.  So quite honestly as a Mac user who is accustomed to a certain level of usability, I would never install this app for that reason alone.
Reblog this post [with Zemanta]



Facebook LinkedIn last.fm Hulu Twitter RSS
Adopt a Pet

Copyright © 2010 Steve Springett