Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert iTunes Playlist to Walkman
require 'rubygems'
music_dir = '/Music'
ARGV.each do |filename|
ext = File.extname(filename).downcase
if ext != '.m3u' || !FileTest.exist?(filename)
next
end
basename = File.basename(filename, ext)
output = '';
data = File.open(filename).read
data.encode!('UTF-8', 'UTF-8-MAC')
data.gsub!(/\r\n|\r/, "\n")
data.each_line do |line|
next if line.strip.empty?
line.encode!('UTF-8', 'UTF-8-MAC')
line.gsub!(/^[^#].*?([^\/]+?\..+?)$/) do |match|
File.join(music_dir, basename, $1)
end
output += line
end
output.gsub!(/\n/, "\r")
File.open(filename, 'w').puts(output)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.