Skip to content

Instantly share code, notes, and snippets.

@jyokyoku
Created November 3, 2014 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyokyoku/443d2d17c27d80bc0985 to your computer and use it in GitHub Desktop.
Save jyokyoku/443d2d17c27d80bc0985 to your computer and use it in GitHub Desktop.
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