andyw8-itunes-library 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +30 -0
- data/lib/itunes/library.rb +69 -0
- data/lib/itunes/playlist.rb +33 -0
- data/lib/itunes/track.rb +143 -0
- metadata +91 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Joshua Peek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
iTunes Library
|
2
|
+
==============
|
3
|
+
|
4
|
+
A Ruby library that makes it easy to dig around your iTunes Library metadata.
|
5
|
+
|
6
|
+
Forked because: https://github.com/josh/itunes-library/issues/5
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
gem install itunes-library
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
require 'itunes/library'
|
17
|
+
library = ITunes::Library.load("~/Music/iTunes/iTunes Library.xml")
|
18
|
+
|
19
|
+
library.playlists.map(&:name) #=> ["90's Music", "Classical Music", "Recently Played", ...]
|
20
|
+
|
21
|
+
library.music.tracks.select { |t| t.artist == "Foo Fighters" }.inject(0) { |n, t| n + t.play_count } #=> 4261
|
22
|
+
|
23
|
+
library.podcasts.tracks.select { |t| t.unplayed? }
|
24
|
+
|
25
|
+
License
|
26
|
+
-------
|
27
|
+
|
28
|
+
Copyright (c) 2011 Joshua Peek.
|
29
|
+
|
30
|
+
Released under the MIT license. See `LICENSE` for details.
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'plist'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'itunes/playlist'
|
5
|
+
require 'itunes/track'
|
6
|
+
|
7
|
+
module ITunes
|
8
|
+
class Library
|
9
|
+
def self.load(file)
|
10
|
+
new(Plist::parse_xml(file))
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(properties)
|
14
|
+
@properties = properties || {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](key)
|
18
|
+
@properties[key]
|
19
|
+
end
|
20
|
+
|
21
|
+
def playlists
|
22
|
+
@playlists ||= self['Playlists'].map { |p| Playlist.new(self, p) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_playlist(name)
|
26
|
+
playlists.detect { |p| p.name == name }
|
27
|
+
end
|
28
|
+
|
29
|
+
def music
|
30
|
+
find_playlist 'Music'
|
31
|
+
end
|
32
|
+
|
33
|
+
def movies
|
34
|
+
find_playlist 'Movies'
|
35
|
+
end
|
36
|
+
|
37
|
+
def tv_shows
|
38
|
+
find_playlist 'TV Shows'
|
39
|
+
end
|
40
|
+
|
41
|
+
def podcasts
|
42
|
+
find_playlist 'Podcasts'
|
43
|
+
end
|
44
|
+
|
45
|
+
def books
|
46
|
+
find_playlist 'Books'
|
47
|
+
end
|
48
|
+
|
49
|
+
def track_ids
|
50
|
+
self['Tracks']
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_track(id)
|
54
|
+
Track.new(self, track_ids[id.to_s])
|
55
|
+
end
|
56
|
+
|
57
|
+
def tracks
|
58
|
+
@tracks ||= self['Tracks'].values.map { |t| Track.new(self, t) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def size
|
62
|
+
track_ids.size
|
63
|
+
end
|
64
|
+
|
65
|
+
def inspect
|
66
|
+
"#<#{self.class.name} size=#{size}>"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ITunes
|
2
|
+
class Playlist
|
3
|
+
def initialize(library, properties)
|
4
|
+
@library = library
|
5
|
+
@properties = properties
|
6
|
+
end
|
7
|
+
|
8
|
+
def [](key)
|
9
|
+
@properties[key]
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
self['Name']
|
14
|
+
end
|
15
|
+
|
16
|
+
def item_ids
|
17
|
+
(self['Playlist Items'] || []).map { |t| t['Track ID'] }
|
18
|
+
end
|
19
|
+
|
20
|
+
def items
|
21
|
+
@items ||= item_ids.map { |id| @library.fetch_track(id) }
|
22
|
+
end
|
23
|
+
alias_method :tracks, :items
|
24
|
+
|
25
|
+
def size
|
26
|
+
item_ids.size
|
27
|
+
end
|
28
|
+
|
29
|
+
def inspect
|
30
|
+
"#<#{self.class.name} name=#{name.inspect} size=#{size}>"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/itunes/track.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
module ITunes
|
2
|
+
class Track
|
3
|
+
def initialize(library, properties)
|
4
|
+
@library = library
|
5
|
+
@properties = properties
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_hash
|
9
|
+
@properties
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
@properties[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def id
|
17
|
+
self['Track ID']
|
18
|
+
end
|
19
|
+
|
20
|
+
def persistent_id
|
21
|
+
self['Persistent ID']
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
self['Name']
|
26
|
+
end
|
27
|
+
|
28
|
+
def artist
|
29
|
+
self['Artist']
|
30
|
+
end
|
31
|
+
|
32
|
+
def album
|
33
|
+
self['Album']
|
34
|
+
end
|
35
|
+
|
36
|
+
def number
|
37
|
+
self['Track Number']
|
38
|
+
end
|
39
|
+
|
40
|
+
def genre
|
41
|
+
self['Genre']
|
42
|
+
end
|
43
|
+
|
44
|
+
def year
|
45
|
+
self['Year']
|
46
|
+
end
|
47
|
+
|
48
|
+
def composer
|
49
|
+
self['Composer']
|
50
|
+
end
|
51
|
+
|
52
|
+
def season_number
|
53
|
+
self['Season']
|
54
|
+
end
|
55
|
+
|
56
|
+
def episode_number
|
57
|
+
self['Episode Order']
|
58
|
+
end
|
59
|
+
|
60
|
+
def date_added
|
61
|
+
self['Date Added']
|
62
|
+
end
|
63
|
+
|
64
|
+
def last_played_at
|
65
|
+
self['Play Date UTC']
|
66
|
+
end
|
67
|
+
|
68
|
+
def play_count
|
69
|
+
self['Play Count'] || 0
|
70
|
+
end
|
71
|
+
|
72
|
+
def total_time
|
73
|
+
self['Total Time'] / 1000
|
74
|
+
end
|
75
|
+
|
76
|
+
def kind
|
77
|
+
self['Kind']
|
78
|
+
end
|
79
|
+
|
80
|
+
def bit_rate
|
81
|
+
self['Bit Rate']
|
82
|
+
end
|
83
|
+
|
84
|
+
def sample_rate
|
85
|
+
self['Sample Rate']
|
86
|
+
end
|
87
|
+
|
88
|
+
def artwork_count
|
89
|
+
self['Artwork Count']
|
90
|
+
end
|
91
|
+
|
92
|
+
def location
|
93
|
+
self['Location']
|
94
|
+
end
|
95
|
+
|
96
|
+
def location_path
|
97
|
+
uri_parser.unescape(location).gsub('file://localhost', '')
|
98
|
+
end
|
99
|
+
|
100
|
+
def audio?
|
101
|
+
!video?
|
102
|
+
end
|
103
|
+
|
104
|
+
def video?
|
105
|
+
self['Has Video'] || false
|
106
|
+
end
|
107
|
+
|
108
|
+
def movie?
|
109
|
+
self['Movie'] || false
|
110
|
+
end
|
111
|
+
|
112
|
+
def tv_show?
|
113
|
+
self['TV Show'] || false
|
114
|
+
end
|
115
|
+
|
116
|
+
def podcast?
|
117
|
+
self['Podcast'] || false
|
118
|
+
end
|
119
|
+
|
120
|
+
def audiobook?
|
121
|
+
kind =~ /Audible/ ? true : false
|
122
|
+
end
|
123
|
+
|
124
|
+
def unplayed?
|
125
|
+
self['Unplayed'] == true || play_count == 0
|
126
|
+
end
|
127
|
+
|
128
|
+
def played?
|
129
|
+
!unplayed?
|
130
|
+
end
|
131
|
+
|
132
|
+
def inspect
|
133
|
+
"#<#{self.class.name} name=#{name.inspect}>"
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def uri_parser
|
139
|
+
# choose appropriate URI class for Ruby 1.9/1.8
|
140
|
+
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: andyw8-itunes-library
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua Peek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: plist
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! ' A Ruby library that makes it easy to dig around your iTunes Library
|
47
|
+
metadata.
|
48
|
+
|
49
|
+
'
|
50
|
+
email:
|
51
|
+
- josh@joshpeek.com
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- lib/itunes/library.rb
|
57
|
+
- lib/itunes/playlist.rb
|
58
|
+
- lib/itunes/track.rb
|
59
|
+
- LICENSE
|
60
|
+
- README.md
|
61
|
+
homepage: https://github.com/andyw8/itunes-library
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: -3361530687575430051
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
hash: -3361530687575430051
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.24
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Wrapper around iTunes Library.xml
|
91
|
+
test_files: []
|