bit of a cleanup

This commit is contained in:
Ward Wouts 2006-02-14 21:13:55 +00:00
parent 8a78b13c31
commit 80f7c27c14

View file

@ -19,7 +19,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
podcasts = {
@podcasts = {
"distortedview" => {
"rss" => 'http://www.distortedview.com/show/index.xml',
"savedir" => '/Users/ward/ipod_sync/[books]/Distorted View',
@ -49,10 +49,20 @@ def fetch(uri_str, limit = 10)
end
end
for podcast in podcasts.keys.sort
def deleteold(podcast)
Dir.open(@podcasts[podcast]["savedir"]).each {|entry|
if File.file?("#{@podcasts[podcast]["savedir"]}/#{entry}") &&
! @filelist[entry]
puts "deleting #{entry}"
File.unlink("#{@podcasts[podcast]["savedir"]}/#{entry}")
end
}
end
for podcast in @podcasts.keys.sort
puts podcast
res = fetch(podcasts[podcast]["rss"])
filelist = {}
res = fetch(@podcasts[podcast]["rss"])
@filelist = {}
xmldoc = REXML::Document.new(res.body)
xmldoc.elements.each("rss/channel/*/enclosure") {|x|
@ -60,26 +70,20 @@ for podcast in podcasts.keys.sort
cast = x.attribute("url").to_s.dup
filename = cast.dup
filename.sub!(/^.*\//, "")
if podcasts[podcast]["rename"]
filename.sub!(podcasts[podcast]["rename"][0], podcasts[podcast]["rename"][1])
if @podcasts[podcast]["rename"]
filename.sub!(@podcasts[podcast]["rename"][0], @podcasts[podcast]["rename"][1])
end
filelist[filename] = true
if ! File.exists?("#{podcasts[podcast]["savedir"]}/#{filename}")
puts "gotta get #{podcasts[podcast]["savedir"]}/#{filename}"
@filelist[filename] = true
if ! File.exists?("#{@podcasts[podcast]["savedir"]}/#{filename}")
puts "gotta get #{@podcasts[podcast]["savedir"]}/#{filename}"
response = fetch(cast)
File.open("#{podcasts[podcast]["savedir"]}/#{filename}", "w"){|f|
File.open("#{@podcasts[podcast]["savedir"]}/#{filename}", "w"){|f|
f.print(response.body)
}
end
end
}
if podcasts[podcast]["delete"]
Dir.open(podcasts[podcast]["savedir"]).each {|entry|
if File.file?("#{podcasts[podcast]["savedir"]}/#{entry}") &&
! filelist[entry]
puts "deleting #{entry}"
File.unlink("#{podcasts[podcast]["savedir"]}/#{entry}")
end
}
if @podcasts[podcast]["delete"]
deleteold(podcast)
end
end