Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit d013afd3f510462c234660c80fc5bae94ed30dd3 1 parent 5b7989a
Andy Waite authored
Showing with 26 additions and 0 deletions.
  1. +1 −0  lib/itunes/library.rb
  2. +15 −0 lib/itunes/track.rb
  3. +10 −0 test/test_itunes.rb
View
1  lib/itunes/library.rb
@@ -1,4 +1,5 @@
require 'plist'
+require 'uri'
require 'itunes/playlist'
require 'itunes/track'
View
15 lib/itunes/track.rb
@@ -77,6 +77,14 @@ def kind
self['Kind']
end
+ def location
+ self['Location']
+ end
+
+ def location_path
+ uri_parser.unescape(location).gsub('file://localhost', '')
+ end
+
def audio?
!video?
end
@@ -112,5 +120,12 @@ def played?
def inspect
"#<#{self.class.name} name=#{name.inspect}>"
end
+
+ private
+
+ def uri_parser
+ # choose appropriate URI class for Ruby 1.9/1.8
+ @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
+ end
end
end
View
10 test/test_itunes.rb
@@ -98,6 +98,16 @@ def test_track_date_added
assert_equal "2010-04-24T13:24:25+00:00", library.fetch_track(7944).date_added.to_s
end
+ def test_track_location
+ expected_location = 'file://localhost/iTunes/iTunes%20Media/Music/Coldplay/Viva%20la%20Vida/10%20Death%20and%20All%20His%20Friends.mp3'
+ assert_equal expected_location, library.fetch_track(7405).location
+ end
+
+ def test_track_location_path
+ expected_path = '/iTunes/iTunes Media/Music/Coldplay/Viva la Vida/10 Death and All His Friends.mp3'
+ assert_equal expected_path, library.fetch_track(7405).location_path
+ end
+
def test_audio_track_total_time
assert_equal 246, library.fetch_track(7944).total_time
end
Please sign in to comment.
Something went wrong with that request. Please try again.