Skip Menu |

This queue is for tickets about the Mac-iTunes-Library CPAN distribution.

Report information
The Basics
Id: 57673
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Mac-iTunes-Library

People
Owner: dinomite [...] cpan.org
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.8
Fixed in: (no value)



Subject: Adding trackCount and trackNumber (with patch)
Attached is a patch to implement trackCount() and trackNumber() methods on Items to capture "Track Count" and "Track Number" data about an iTunes item. Thanks for writing this module. My friend wanted to make a playlist of all the complete albums in his iTunes (those which contain every track of the album) and this saved us a lot of XML dreariness.
Subject: 0001-Add-trackCount-and-trackNumber-item-data-methods.patch
From 0673c4476180ed3e04c0cdcb4f4385c113ea72d8 Mon Sep 17 00:00:00 2001 From: Michael G. Schwern <schwern@pobox.com> Date: Wed, 19 May 2010 22:36:20 -0700 Subject: [PATCH] Add trackCount() and trackNumber() item data methods --- lib/Mac/iTunes/Library/Item.pm | 44 ++++++++++++++++++++++++++++++++++++++++ t/Item.t | 8 +++++- t/Library.t | 4 ++- t/iTunes_Music_Library.xml | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/Mac/iTunes/Library/Item.pm b/lib/Mac/iTunes/Library/Item.pm index a79d57a..a7bd875 100644 --- a/lib/Mac/iTunes/Library/Item.pm +++ b/lib/Mac/iTunes/Library/Item.pm @@ -123,6 +123,8 @@ sub new { 'Location' => undef, 'File Folder Count' => undef, 'Library Folder Count' => undef, + 'Track Count' => undef, + 'Track Number' => undef, }; bless $self, $class; @@ -160,6 +162,8 @@ sub new { elsif ($param eq 'Location') { location($self, $params{'Location'}) } elsif ($param eq 'File Folder Count') { fileFolderCount($self, $params{'File Folder Count'}) } elsif ($param eq 'Library Folder Count') { libraryFolderCount($self, $params{'Library Folder Count'}) } + elsif ($param eq 'Track Count') { trackCount($self, $params{'Track Count'}) } + elsif ($param eq 'Track Number') { trackNumber($self, $params{'Track Number'}) } else { print "Param that I can't handle: $param\n" } } @@ -707,6 +711,46 @@ sub libraryFolderCount { } #libraryFolderCount +=head2 trackCount( $trackCount ) + +Get/set the Track Count attribute for this item. + +=cut + +sub trackCount { + my $self = shift; + + if (@_) { + my $trackCount = shift; + return carp "$trackCount isn't a valid Track Count" + unless _checkNum($trackCount); + $self->{'Track Count'} = $trackCount; + } + + return $self->{'Track Count'}; +} #trackCount + + +=head2 trackNumber( $trackNumber ) + +Get/set the Track Number attribute for this item. + +=cut + +sub trackNumber { + my $self = shift; + + if (@_) { + my $trackNumber = shift; + return carp "$trackNumber isn't a valid Track Number" + unless _checkNum($trackNumber); + $self->{'Track Number'} = $trackNumber; + } + + return $self->{'Track Number'}; +} #trackNumber + + ##### Support methods ##### # Is it a number? sub _checkNum { diff --git a/t/Item.t b/t/Item.t index 62f8f60..9d0f951 100755 --- a/t/Item.t +++ b/t/Item.t @@ -12,7 +12,7 @@ $Author: drewgstephens $ ######################### use lib "."; use 5; -use Test::More tests => 32; +use Test::More tests => 34; BEGIN { use_ok('Mac::iTunes::Library::Item') }; ######################### @@ -46,7 +46,9 @@ my %values = ( 'Track Type' => 'File', 'Location' => 'file://localhost/Users/dinomite/Music/Artist%20Name/Track%20Name.mp3', 'File Folder Count' => 4, - 'Library Folder Count' => 1 + 'Library Folder Count' => 1, + 'Track Number' => 3, + 'Track Count' => 21, ); # Create a new item @@ -86,3 +88,5 @@ is($item->trackType(), $values{'Track Type'}, 'Get Track Type'); is($item->location(), $values{'Location'}, 'Get Location'); is($item->fileFolderCount(), $values{'File Folder Count'}, 'Get File Folder Count'); is($item->libraryFolderCount(), $values{'Library Folder Count'}, 'Get Total Time'); +is($item->trackCount(), $values{'Track Count'}, 'Get Track Count'); +is($item->trackNumber(), $values{'Track Number'}, 'Get Track Number'); diff --git a/t/Library.t b/t/Library.t index 0bda11d..8fdcbaa 100755 --- a/t/Library.t +++ b/t/Library.t @@ -4,7 +4,7 @@ ######################### use lib "./lib"; use 5; -use Test::More tests => 21; +use Test::More tests => 23; BEGIN { use_ok('Mac::iTunes::Library'); use_ok('Mac::iTunes::Library::Item'); @@ -47,3 +47,5 @@ is($items{'ATB'}{'Push the Limits'}[0]->persistentID(), 'DAC2FC501CCA2031', 'Item Persistent ID'); is($items{'ATB'}{'Push the Limits'}[0]->libraryFolderCount(), '1', 'Item Library Folder Count'); +is($items{'Deep Forest'}{'Freedom Cry'}[0]->trackNumber, 8, 'Track Number'); +is($items{'Deep Forest'}{'Freedom Cry'}[0]->trackCount, 18, 'Track Count'); diff --git a/t/iTunes_Music_Library.xml b/t/iTunes_Music_Library.xml index 1582fe3..7a5c864 100755 --- a/t/iTunes_Music_Library.xml +++ b/t/iTunes_Music_Library.xml @@ -162,6 +162,7 @@ time is 70m9s. <key>Size</key><integer>3201107</integer> <key>Total Time</key><integer>200045</integer> <key>Track Number</key><integer>8</integer> + <key>Track Count</key><integer>18</integer> <key>Date Modified</key><date>2005-02-21T12:40:15Z</date> <key>Date Added</key><date>2004-11-18T15:00:41Z</date> <key>Bit Rate</key><integer>128</integer> -- 1.7.0.3
On Thu May 20 13:08:31 2010, MSCHWERN wrote: Show quoted text
> Attached is a patch to implement trackCount() and trackNumber() methods > on Items to capture "Track Count" and "Track Number" data about an > iTunes item. > > Thanks for writing this module. My friend wanted to make a playlist of > all the complete albums in his iTunes (those which contain every track > of the album) and this saved us a lot of XML dreariness.
Thanks for the patch! I'll try to get it integrated this weekend. -Drew
Release with v0.9