Created
September 22, 2011 15:23
-
-
Save mblsha/1235052 to your computer and use it in GitHub Desktop.
Copies all files from an iTunes playlist to new folder
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
#!/usr/bin/env ruby -wKU | |
# PREREQUISITES: sudo gem install rb-appscript | |
require 'rubygems' | |
require 'appscript' | |
require 'fileutils' | |
require 'pathname' | |
if ARGV.length != 1 | |
playlists = Appscript.app('iTunes').playlists.get.map { |p| "\"#{p.name.get}\"" } | |
puts "USAGE: extract-itunes-playlist.rb PLAYLIST_NAME" | |
puts "Available playlists: #{playlists.join(', ')}" | |
exit 0 | |
end | |
selected_playlist = ARGV[0] | |
itunes = Appscript.app('iTunes') | |
itunes.playlists.get.each do |playlist| | |
next if playlist.name.get != selected_playlist | |
FileUtils::Verbose::mkdir_p(selected_playlist) | |
count = 1 | |
playlist.tracks.get.each do |track| | |
orig_filename = track.location.get.to_s | |
pathname = Pathname.new(orig_filename) | |
dest_filename = sprintf("%04d#{pathname.extname}", count) | |
FileUtils::Verbose::cp(orig_filename, "#{selected_playlist}/#{dest_filename}") | |
count += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment