diff --git a/getdistorted/getdistorted.rb b/getdistorted/getdistorted.rb index 14ffff0..1328547 100755 --- a/getdistorted/getdistorted.rb +++ b/getdistorted/getdistorted.rb @@ -33,6 +33,8 @@ "rename" => [ /_(\d\d\d\d)(\d\d)/, '\2\1' ], # directory to put symlinks to the new files "linkdir" => '/Users/ward/ipod_sync/[books]/Distorted View', + # option to write an m3u file after fetching the mp3s + "m3u" => '/Users/ward/dv.m3u', }, "tagesschau" => { "rss" => 'http://www.tagesschau.de/export/podcast', @@ -91,23 +93,34 @@ def getenclosure(podcast, enclosure) if @podcasts[podcast]["linkdir"] File.symlink("#{@podcasts[podcast]["savedir"]}/#{filename}", "#{@podcasts[podcast]["linkdir"]}/#{filename}") end + return "#{@podcasts[podcast]["savedir"]}/#{filename}" rescue Timeout::Error, Errno::EHOSTUNREACH, Errno::ECONNREFUSED puts " error fetching, skipping" end + else + return "#{@podcasts[podcast]["savedir"]}/#{filename}" end end end for podcast in @podcasts.keys.sort + files = Array.new puts podcast res = fetch(@podcasts[podcast]["rss"]) @filelist = {} xmldoc = REXML::Document.new(res.body) xmldoc.elements.each("rss/channel/*/enclosure") {|enclosure| - getenclosure(podcast, enclosure) + files.push getenclosure(podcast, enclosure) } if @podcasts[podcast]["delete"] deleteold(podcast) end + if @podcasts[podcast]["m3u"] + File.open(@podcasts[podcast]["m3u"], "w"){|f| + files.each{|file| + f.puts file + } + } + end end