Created
November 3, 2014 19:59
-
-
Save jyokyoku/443d2d17c27d80bc0985 to your computer and use it in GitHub Desktop.
Convert iTunes Playlist to Walkman
This file contains hidden or 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
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