Skip to content

Copy Files from iTunes Playlist Util Script

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 =[0], mode: 'r', binmode: true, external_encoding: Encoding::UTF_16LE)
dest =[1])
if dest.nil? || dest == ""
  STDERR.puts "destination can't be blank"
  exit 1
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

Posted in Ruby, Tips and Tricks.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.