m3u吐き出し
usage:ruby コピペしたソース 検索ディレクトリ
指定配下のメディアファイルをm3u拡張子のテキストでカレントにはき出します。
$OK_EXT = ["mp3","m4a","flv","mp2","ape","flac","iso","mp4","mka","tta","wav"]
で定義されたフィルターがかかります
$DEBUGはperlライクなのを書いてみたかったから
nextはとても助かる仕組みです。
あと、
hoge = 0 if(hoge) puts "0はtrue評価です" end
な違和感のある何か。
ともかくrubyは1.8で。
#! /usr/bin/ruby # -*- coding: utf-8 -*- $DEBUG = false $OK_EXT = ["mp3","m4a","flv","mp2","ape","flac","iso","mp4","mka","tta","wav"] #検索対象パスなければおしまい。 if (ARGV[0] == nil) puts "検索対象パスを下さいな" exit end #ディレクトリのエントリ開いて走査。dirならで自分呼ぶ違うなら書き込みメソッド呼ぶ def getFile(dir,io) Dir::entries(dir).each.each do |en| next if en == "." or en == ".." or en == ".DS_Store" if FileTest.file?(dir + "/" + en) puts "file:" + en if $DEBUG writePath(io,dir + "/" + en) else puts "directory:" + en if $DEBUG getFile(dir + "/" + en,io) end end end #ファイルパスを書き込む def writePath(io,filepath) if(typefilters(filepath)) io.puts(filepath) if not $DEBUG puts filepath if $DEBUG else puts "not supported type.." if $DEBUG end end #filter def typefilters(filepath) return $OK_EXT.index(File::extname(filepath).gsub(/\./,"")) end #書き出し File.open("./playlistabout\.m3u",'w'){ |io| getFile(ARGV[0].gsub(/\/$/,""),io) }