itunes_csv 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/bin/itunes_csv +7 -0
- data/itunes_csv.gemspec +18 -0
- data/lib/itunes_csv/version.rb +3 -0
- data/lib/itunes_csv.rb +43 -0
- data/spec/fixtures/library.xml +4276 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andy Waite
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# iTunes CSV
|
2
|
+
|
3
|
+
Export iTunes Library XML data to CSV
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install itunes_csv
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ itunes_csv --help
|
12
|
+
Usage: itunes_csv [options]
|
13
|
+
-f, --fields name,track,year List of fields(default: name,artist)
|
14
|
+
-p, --path PATH Path to iTunes XML file (default: ~/Music/iTunes/iTunes Music Library.xml)
|
15
|
+
|
16
|
+
## Notes
|
17
|
+
|
18
|
+
May take a long time to run for a large iTunes library (10,000+ tracks)
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
1. Fork it
|
23
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
24
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
25
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
26
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/itunes_csv
ADDED
data/itunes_csv.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/itunes_csv/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Andy Waite"]
|
6
|
+
gem.email = ["github.aw@andywaite.com"]
|
7
|
+
gem.description = "Export iTunes Library XML data to CSV"
|
8
|
+
gem.summary = "Export iTunes Library XML data to CSV"
|
9
|
+
gem.homepage = "https://github.com/andyw8/itunes_csv"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "itunes_csv"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ItunesCsv::VERSION
|
17
|
+
gem.add_runtime_dependency "itunes-library"
|
18
|
+
end
|
data/lib/itunes_csv.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "itunes_csv/version"
|
2
|
+
require "itunes/library"
|
3
|
+
require "csv"
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
module ItunesCsv
|
7
|
+
class CommandLine
|
8
|
+
def self.invoke(args)
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
opts = OptionParser.new do |opts|
|
12
|
+
options[:fields] = ['name', 'artist']
|
13
|
+
opts.on( '-f', '--fields name,track,year', Array, "List of fields (default: #{options[:fields].join(',')})" ) do |list|
|
14
|
+
options[:fields] = list
|
15
|
+
end
|
16
|
+
|
17
|
+
options[:path] = '~/Music/iTunes/iTunes Music Library.xml'
|
18
|
+
opts.on( '-p', '--path PATH', "Path to iTunes XML file (default: #{options[:path]})" ) do |path|
|
19
|
+
options[:path] = path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.parse!
|
24
|
+
|
25
|
+
library_path = File.expand_path(options[:path])
|
26
|
+
library = ITunes::Library.load(library_path)
|
27
|
+
csv_string = CSV.generate do |csv|
|
28
|
+
csv << options[:fields]
|
29
|
+
library.music.tracks.each do |t|
|
30
|
+
row = options[:fields].map do |f|
|
31
|
+
unless t.respond_to?(f.to_sym)
|
32
|
+
puts "Unknown field: #{f}"
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
t.send(f.to_sym)
|
36
|
+
end
|
37
|
+
csv << row
|
38
|
+
end
|
39
|
+
end
|
40
|
+
puts csv_string
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|