Created
November 29, 2012 17:55
-
-
Save kch/4170764 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'appscript' | |
require 'pathname' | |
include Appscript | |
### Usage: | |
# ./itunes-mk-playlist.rb \ | |
# ~/"Music/iTunes/iTunes Media/Music/Atomine Elektrine/Zektor X/09 ...and Ever.mp3" \ | |
# ~/"Music/iTunes/iTunes Media/Music/DarkDriveClinic/Noise in My Head/09 Angel of Malcontent.m4a" \ | |
# ~/"Music/iTunes/iTunes Media/Music/Rome/Die Aesthetik Der Herrschaftsfreiheit - Band 1/02 The Angry Brigade.mp3" \ | |
# ~/"Music/iTunes/iTunes Media/Music/The Submarines/Love Notes_Letter Bombs/10 Anymore.mp3" | |
paths = ARGV.map { |s| Pathname.new(s).realpath.to_s } | |
itunes = app('iTunes') | |
name = "jwz-#{Time.now.strftime("%Y-%m-%d %H:%M")}" | |
playlist = itunes.make(:new => :user_playlist, :with_properties => {:name => name}) | |
library = itunes.tracks.get.inject({}) { |h, t| h[t.location.get.to_s] = t; h } | |
tracks = paths.map { |path| library[path] }.compact | |
tracks.each { |track| itunes.duplicate(track, :to => playlist) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll want to
gem install rb-appscript
first.