A while ago, I found myself wanting to copy the files of an iTunes playlist. If the files are not in the same directory, or handful of directories, this can get tedious in a hurry.
Fret not: here’s a script to make your life easier. First, export your playlist as “Unicode Text
“. Next, put the script below in a file such as “cp_it_pl.rb
“. Then run it like:
$ cp_it_pl.rb my_playlist.txt cool_music/
Note: this script runs on Ruby 1.9+
require 'fileutils' playlist = File.read(ARGV[0], mode: 'r', binmode: true, external_encoding: Encoding::UTF_16LE) dest = Dir.new(ARGV[1]) if dest.nil? || dest == "" STDERR.puts "destination can't be blank" exit 1 end utf8_playlist = playlist.encode("UTF-8") utf8_playlist.each_line("\r") do |line| path = line.split("\t")[-1].chomp.split(":")[1..-1].join("/") next if path.nil? || path == "" abs_path = "/" + path puts "copying "+abs_path.inspect+" to "+dest.path FileUtils.cp abs_path, dest end |
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.