graphtunes 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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-05-03
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yossef Mendelssohn
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/Manifest.txt ADDED
@@ -0,0 +1,20 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/graphtunes.rb
9
+ lib/graphtunes/version.rb
10
+ script/console
11
+ script/destroy
12
+ script/generate
13
+ setup.rb
14
+ spec/graphtunes_spec.rb
15
+ spec/spec.opts
16
+ spec/spec_helper.rb
17
+ tasks/deployment.rake
18
+ tasks/environment.rake
19
+ tasks/rspec.rake
20
+ tasks/website.rake
data/README.txt ADDED
@@ -0,0 +1,8 @@
1
+ graphtunes is for visualization of music playlist data
2
+
3
+ At the moment, it only makes a line graph of the BPM data for a playlist, and it expects as input an XML-exported iTunes playlist[1].
4
+
5
+ It uses REXML to parse the playlist (stdlib, yay) and gruff for the graphing (enjoy installing RMagick and friends if you haven't already).
6
+
7
+
8
+ [1]: in iTunes, select a playlist, right-click (or ctrl-click, or two-finger tap, or whatever) on the playlist, choose Export Song List..., XML format
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'graphtunes/version'
2
+
3
+ AUTHOR = 'Yossef Mendelssohn' # can also be an array of Authors
4
+ EMAIL = "ymendel@pobox.com"
5
+ DESCRIPTION = "for visualization of music playlist data"
6
+ GEM_NAME = 'graphtunes' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'yomendel' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['gruff', '>= 0.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = Graphtunes::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'graphtunes documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,9 @@
1
+ module Graphtunes #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/graphtunes.rb ADDED
@@ -0,0 +1,108 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rexml/document'
5
+ require 'gruff'
6
+
7
+ module Graphtunes
8
+ class << self
9
+ def process(file)
10
+ data = import(file)
11
+ graph(data, file.chomp('.xml') + '.png')
12
+ end
13
+
14
+ def import(file)
15
+ raise TypeError, "'#{file}' is not a file" unless File.file?(file)
16
+ get_track_list(File.read(file))
17
+ end
18
+
19
+ def get_track_list(data)
20
+ doc = REXML::Document.new(data)
21
+
22
+ track_list = nil
23
+ doc.elements.each('plist/dict/key') do |el|
24
+ if el.text == 'Tracks'
25
+ track_list = el.next_element
26
+ end
27
+ end
28
+
29
+ raise 'No track list information found' unless track_list
30
+
31
+ tracks = get_tracks(track_list)
32
+ order = get_track_order(doc)
33
+ order_tracks(tracks, order)
34
+ end
35
+
36
+ def get_tracks(data)
37
+ track_data = {}
38
+ data.elements.each('key') do |key|
39
+ track_id = key.text
40
+ track = key.next_element
41
+ track_data[track_id] = extract_track_data(track)
42
+ end
43
+ track_data
44
+ end
45
+
46
+ def extract_track_data(data)
47
+ track_data = {}
48
+ data.elements.each('key') do |key|
49
+ field = key.text
50
+ if extraction_fields.include?(field)
51
+ value = key.next_element.text
52
+ value = value.to_i if field == 'BPM'
53
+ track_data[field] = value
54
+ end
55
+ end
56
+ track_data
57
+ end
58
+
59
+ def get_track_order(data)
60
+ playlists = nil
61
+ data.elements.each('plist/dict/key') do |el|
62
+ if el.text == 'Playlists'
63
+ playlists = el.next_element
64
+ end
65
+ end
66
+
67
+ items = nil
68
+ playlists.elements.each('dict/key') do |el|
69
+ if el.text == 'Playlist Items'
70
+ items = el.next_element
71
+ end
72
+ end
73
+
74
+ order = []
75
+
76
+ items.elements.each('dict') do |dict|
77
+ dict.elements.each('key') do |key|
78
+ if key.text == 'Track ID'
79
+ order.push(key.next_element.text)
80
+ end
81
+ end
82
+ end
83
+
84
+ order
85
+ end
86
+
87
+ def order_tracks(tracks, order)
88
+ ordered = []
89
+ order.each do |i|
90
+ ordered.push(tracks[i])
91
+ end
92
+ ordered
93
+ end
94
+
95
+ def graph(data, file)
96
+ graph = Gruff::Line.new
97
+ graph.data('BPM', data.collect { |t| t['BPM'] })
98
+ graph.hide_dots = true
99
+ graph.write(file)
100
+ end
101
+
102
+ private
103
+
104
+ def extraction_fields
105
+ ['Track ID', 'Name', 'Artist', 'Album', 'BPM']
106
+ end
107
+ end
108
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/graphtunes.rb'}"
9
+ puts "Loading graphtunes gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)