Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 3 files changed
  • 0 comments
  • 2 contributors
Apr 04, 2012
Andy Waite Adding support for track location
Track#location with return the raw location (a file:// URI)
Track#location_path will convert the location to a standard file path
d013afd
Andy Waite Fixing whitespace ce66f7c
Joshua Peek Merge pull request #3 from andyw8/track-location
Track location
5630580
1  lib/itunes/library.rb
... ... @@ -1,4 +1,5 @@
1 1 require 'plist'
  2 +require 'uri'
2 3
3 4 require 'itunes/playlist'
4 5 require 'itunes/track'
15 lib/itunes/track.rb
@@ -77,6 +77,14 @@ def kind
77 77 self['Kind']
78 78 end
79 79
  80 + def location
  81 + self['Location']
  82 + end
  83 +
  84 + def location_path
  85 + uri_parser.unescape(location).gsub('file://localhost', '')
  86 + end
  87 +
80 88 def audio?
81 89 !video?
82 90 end
@@ -112,5 +120,12 @@ def played?
112 120 def inspect
113 121 "#<#{self.class.name} name=#{name.inspect}>"
114 122 end
  123 +
  124 + private
  125 +
  126 + def uri_parser
  127 + # choose appropriate URI class for Ruby 1.9/1.8
  128 + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
  129 + end
115 130 end
116 131 end
10 test/test_itunes.rb
@@ -98,6 +98,16 @@ def test_track_date_added
98 98 assert_equal "2010-04-24T13:24:25+00:00", library.fetch_track(7944).date_added.to_s
99 99 end
100 100
  101 + def test_track_location
  102 + expected_location = 'file://localhost/iTunes/iTunes%20Media/Music/Coldplay/Viva%20la%20Vida/10%20Death%20and%20All%20His%20Friends.mp3'
  103 + assert_equal expected_location, library.fetch_track(7405).location
  104 + end
  105 +
  106 + def test_track_location_path
  107 + expected_path = '/iTunes/iTunes Media/Music/Coldplay/Viva la Vida/10 Death and All His Friends.mp3'
  108 + assert_equal expected_path, library.fetch_track(7405).location_path
  109 + end
  110 +
101 111 def test_audio_track_total_time
102 112 assert_equal 246, library.fetch_track(7944).total_time
103 113 end

No commit comments for this range

Something went wrong with that request. Please try again.