bit of a cleanup
This commit is contained in:
parent
8a78b13c31
commit
80f7c27c14
1 changed files with 22 additions and 18 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
podcasts = {
|
@podcasts = {
|
||||||
"distortedview" => {
|
"distortedview" => {
|
||||||
"rss" => 'http://www.distortedview.com/show/index.xml',
|
"rss" => 'http://www.distortedview.com/show/index.xml',
|
||||||
"savedir" => '/Users/ward/ipod_sync/[books]/Distorted View',
|
"savedir" => '/Users/ward/ipod_sync/[books]/Distorted View',
|
||||||
|
|
@ -49,10 +49,20 @@ def fetch(uri_str, limit = 10)
|
||||||
end
|
end
|
||||||
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
|
puts podcast
|
||||||
res = fetch(podcasts[podcast]["rss"])
|
res = fetch(@podcasts[podcast]["rss"])
|
||||||
filelist = {}
|
@filelist = {}
|
||||||
|
|
||||||
xmldoc = REXML::Document.new(res.body)
|
xmldoc = REXML::Document.new(res.body)
|
||||||
xmldoc.elements.each("rss/channel/*/enclosure") {|x|
|
xmldoc.elements.each("rss/channel/*/enclosure") {|x|
|
||||||
|
|
@ -60,26 +70,20 @@ for podcast in podcasts.keys.sort
|
||||||
cast = x.attribute("url").to_s.dup
|
cast = x.attribute("url").to_s.dup
|
||||||
filename = cast.dup
|
filename = cast.dup
|
||||||
filename.sub!(/^.*\//, "")
|
filename.sub!(/^.*\//, "")
|
||||||
if podcasts[podcast]["rename"]
|
if @podcasts[podcast]["rename"]
|
||||||
filename.sub!(podcasts[podcast]["rename"][0], podcasts[podcast]["rename"][1])
|
filename.sub!(@podcasts[podcast]["rename"][0], @podcasts[podcast]["rename"][1])
|
||||||
end
|
end
|
||||||
filelist[filename] = true
|
@filelist[filename] = true
|
||||||
if ! File.exists?("#{podcasts[podcast]["savedir"]}/#{filename}")
|
if ! File.exists?("#{@podcasts[podcast]["savedir"]}/#{filename}")
|
||||||
puts "gotta get #{podcasts[podcast]["savedir"]}/#{filename}"
|
puts "gotta get #{@podcasts[podcast]["savedir"]}/#{filename}"
|
||||||
response = fetch(cast)
|
response = fetch(cast)
|
||||||
File.open("#{podcasts[podcast]["savedir"]}/#{filename}", "w"){|f|
|
File.open("#{@podcasts[podcast]["savedir"]}/#{filename}", "w"){|f|
|
||||||
f.print(response.body)
|
f.print(response.body)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
if podcasts[podcast]["delete"]
|
if @podcasts[podcast]["delete"]
|
||||||
Dir.open(podcasts[podcast]["savedir"]).each {|entry|
|
deleteold(podcast)
|
||||||
if File.file?("#{podcasts[podcast]["savedir"]}/#{entry}") &&
|
|
||||||
! filelist[entry]
|
|
||||||
puts "deleting #{entry}"
|
|
||||||
File.unlink("#{podcasts[podcast]["savedir"]}/#{entry}")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue