maak DATE substitutie in filenames mogelijk (dit omdat pennradio idiote filenames heeft)
This commit is contained in:
parent
8a9360e70d
commit
62f666dd4e
1 changed files with 26 additions and 5 deletions
|
|
@ -42,6 +42,14 @@
|
|||
# delete files that aren't in the rss anylonger
|
||||
"delete" => true,
|
||||
},
|
||||
"pennradio" => {
|
||||
"rss" => 'http://www.923freefm.com/pages/podcast/80.rss',
|
||||
# %%DATE%% is a magic word here, gets replaced by the pubdate in
|
||||
# YYYYMMDD format. Won't work if there is no pubDate in the rss feed
|
||||
"rename" => [ /^/, '%%DATE%%-' ],
|
||||
"savedir" => '/Users/ward/Private/mp3/[books]/PennRadio',
|
||||
"linkdir" => '/Users/ward/ipod_sync/[books]/PennRadio',
|
||||
},
|
||||
}
|
||||
|
||||
########################################
|
||||
|
|
@ -50,6 +58,7 @@
|
|||
require 'net/http'
|
||||
require 'uri'
|
||||
require 'rexml/document'
|
||||
require 'date'
|
||||
|
||||
def fetch(uri_str, limit = 10)
|
||||
# You should choose better exception.
|
||||
|
|
@ -74,13 +83,25 @@ def deleteold(podcast)
|
|||
}
|
||||
end
|
||||
|
||||
def getenclosure(podcast, enclosure)
|
||||
if ! enclosure.attribute("url").nil?
|
||||
def getenclosure(podcast, item)
|
||||
enclosure = item.get_elements("enclosure")[0]
|
||||
pubdate = item.get_elements("pubDate")[0]
|
||||
date = nil
|
||||
if ! enclosure.nil?
|
||||
end
|
||||
if ! pubdate.nil?
|
||||
date = Date.parse(pubdate.text).strftime("%Y%m%d")
|
||||
end
|
||||
if ! enclosure.nil? && ! enclosure.attribute("url").nil?
|
||||
cast = enclosure.attribute("url").to_s.dup
|
||||
filename = cast.dup
|
||||
filename.sub!(/^.*\//, "")
|
||||
if @podcasts[podcast]["rename"]
|
||||
filename.sub!(@podcasts[podcast]["rename"][0], @podcasts[podcast]["rename"][1])
|
||||
replacement = @podcasts[podcast]["rename"][1].dup
|
||||
if replacement.match(/%%DATE%%/)
|
||||
replacement.sub!(/%%DATE%%/, date)
|
||||
end
|
||||
filename.sub!(@podcasts[podcast]["rename"][0], replacement)
|
||||
end
|
||||
@filelist[filename] = true
|
||||
if ! File.exists?("#{@podcasts[podcast]["savedir"]}/#{filename}")
|
||||
|
|
@ -110,8 +131,8 @@ for podcast in @podcasts.keys.sort
|
|||
@filelist = {}
|
||||
|
||||
xmldoc = REXML::Document.new(res.body)
|
||||
xmldoc.elements.each("rss/channel/*/enclosure") {|enclosure|
|
||||
files.push getenclosure(podcast, enclosure)
|
||||
xmldoc.elements.each("rss/channel/item") {|item|
|
||||
files.push getenclosure(podcast, item)
|
||||
}
|
||||
if @podcasts[podcast]["delete"]
|
||||
deleteold(podcast)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue