Created
April 30, 2012 20:19
-
-
Save tmcw/2562362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Canvas = require('canvas'), | |
_ = require('underscore'), | |
fs = require('fs'); | |
var w = 800, | |
h = 500; | |
var c = new Canvas(w, h); | |
var ctx = c.getContext('2d'); | |
ctx.fillStyle = '#fff'; | |
ctx.fillRect(0, 0, w, h); | |
ctx.fillStyle = '#000'; | |
ctx.font = '28pt Helvetica'; | |
ctx.globalAlpha = 0.01; | |
var linewidth = 13; | |
var lineheight = 50; | |
var f = fs.readFileSync('itunes.csv', 'utf8'); | |
var lines = f.split(/\n/).slice(1).map(function(l) { | |
var lines = ''; | |
var name = l.split(',')[1]; | |
if (name) { | |
var words = name.split(/\s+/); | |
var line = ''; | |
var level = 50; | |
for (var i = 0; i < words.length; i++) { | |
if (line.length > linewidth) { | |
ctx.fillText(line, 10, level); | |
line = ''; | |
level += lineheight; | |
} | |
line += words[i] + ' '; | |
} | |
if (line) { | |
ctx.fillText(line, 10, level); | |
} | |
} | |
}); | |
fs.writeFileSync('names.png', c.toBuffer()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'osx/cocoa' | |
require 'rubygems' | |
require 'fastercsv' | |
FasterCSV.open("itunes.csv", "w") do |csv| | |
csv << ['artist', 'name', 'plays', 'totaltime'] | |
OSX.load_plist(File.read(ARGV[0]))['Tracks'].each do |id, info| | |
csv << [info['Artist'], info['Name'], info['Play Count'], info['Total Time']] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment