Skip to content

Instantly share code, notes, and snippets.

@tom-a
Created February 19, 2014 16:25
Show Gist options
  • Save tom-a/9095563 to your computer and use it in GitHub Desktop.
Save tom-a/9095563 to your computer and use it in GitHub Desktop.
mp3のプレイリストを、アルバム順にランダムに並び替える
#!/usr/local/bin/ruby
#$Id: reorder.rb,v 1.2 2003/02/17 18:34:10 tom-a Exp tom-a $
# m3uファイルを読み込んで、パス名で1ブロックとしてランダム出力
# albamが同じパス名のファイル群を収納する配列
# listはalbamを収納する配列
$KCODE="sjis"
prevpath = ""
albam = []
list =[]
while gets
currentpath = $_[/.*\\/]
if prevpath == currentpath then
albam += [$_]
else
list += [albam]
albam = [$_]
end
prevpath = currentpath
end
list += [albam]
while list.size > 0
i = rand(list.size-1)
print list[i]
list.delete_at(i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment