iTunes Track class in C# and PHP

  • September 8, 2010
  • James Skemp
  • article

I've recently begun reading up on PHP again. As I'm most fond of my iTunes Playlists to Xml application, I thought I'd work with that application's output - XML files with playlist data - as I continued to dig into PHP (instead of stopping now that I know enough to tweak existing code and create new functionality).

Here's a basic Track object in C# and PHP. I'll of course be elaborating on these as time goes by (and already have code for the C# implementation).

Track class in C#

/// <summary>
/// Music track object.
/// </summary>
public class Track {
	#region Properties
	/// <summary>
	/// How long the track is.
	/// </summary>
	public String Time { get; set; }
	/// <summary>
	/// Name or title of the track.
	/// </summary>
	public String Name { get; set; }
	/// <summary>
	/// Name of the artist.
	/// </summary>
	public String Artist { get; set; }
	/// <summary>
	/// Rating assigned to the track by the playlist's owner.
	/// </summary>
	public int Rating { get; set; }
	/// <summary>
	/// Number of times the track has been played.
	/// </summary>
	public int PlayCount { get; set; }
	/// <summary>
	/// Date and time the track was last played (and finished).
	/// </summary>
	public DateTime LastPlayed { get; set; }
	/// <summary>
	/// Name of the album the track is from.
	/// </summary>
	public String Album { get; set; }
	/// <summary>
	/// True if the album the track is on is a compilation, false otherwise.
	/// </summary>
	public Boolean Compilation { get; set; }
	/// <summary>
	/// Order this track is on the album.
	/// </summary>
	public int TrackNumber { get; set; }
	/// <summary>
	/// Total number of tracks on the album.
	/// </summary>
	public int TrackCount { get; set; }
	/// <summary>
	/// The album disc the track is on.
	/// </summary>
	public int DiscNumber { get; set; }
	/// <summary>
	/// Total number of discs in the album.
	/// </summary>
	public int DiscCount { get; set; }
	/// <summary>
	/// Year the track/album was released/published.
	/// </summary>
	public int Year { get; set; }
	/// <summary>
	/// Genre of music the track falls into.
	/// </summary>
	public String Genre { get; set; }
	/// <summary>
	/// Date and time the track was added.
	/// </summary>
	public DateTime DateAdded { get; set; }
	#endregion
}

Track class in PHP

<?php
/**
 * Music track object.
 *
 * @author James Skemp
 */
class Track {
	/**
	 * How long the track is.
	 * @var string
	 */
	var $Time;
	/**
	 * Name or title of the track.
	 * @var string
	 */
	var $Name;
	/**
	 * Name of the artist.
	 * @var string
	 */
	var $Artist;
	/**
	 * Rating assigned to the track by the playlist's owner.
	 * @var int
	 */
	var $Rating;
	/**
	 * Number of times the track has been played.
	 * @var int
	 */
	var $PlayCount;
	/**
	 * Date and time the track was last played (and finished).
	 */
	var $LastPlayed;
	/**
	 * Name of the album the track is from.
	 * @var string
	 */
	var $Album;
	/**
	 * True if the album the track is on is a compilation, false otherwise.
	 * @var bool
	 */
	var $Compilation;
	/**
	 * Order this track is on the album.
	 * @var int
	 */
	var $TrackNumber;
	/**
	 * Total number of tracks on the album.
	 * @var int
	 */
	var $TrackCount;
	/**
	 * The album disc the track is on.
	 * @var int
	 */
	var $DiscNumber;
	/**
	 * Total number of discs in the album.
	 * @var int
	 */
	var $DiscCount;
	/**
	 * Year the track/album was released/published.
	 * @var int
	 */
	var $Year;
	/**
	 * Genre of music the track falls into.
	 * @var string
	 */
	var $Genre;
	/**
	 * Date and time the track was added.
	 */
	var $DateAdded;
//todo

} ?>

Comments appreciated.