itunes_csv 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itunes_csv.gemspec
4
+ gemspec
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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/itunes_csv ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'itunes_csv'
6
+
7
+ ItunesCsv::CommandLine.invoke ARGV
@@ -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
@@ -0,0 +1,3 @@
1
+ module ItunesCsv
2
+ VERSION = "0.0.1"
3
+ 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