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 files that aren't in the rss anylonger
|
||||||
"delete" => true,
|
"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 'net/http'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require 'rexml/document'
|
require 'rexml/document'
|
||||||
|
require 'date'
|
||||||
|
|
||||||
def fetch(uri_str, limit = 10)
|
def fetch(uri_str, limit = 10)
|
||||||
# You should choose better exception.
|
# You should choose better exception.
|
||||||
|
|
@ -74,13 +83,25 @@ def deleteold(podcast)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def getenclosure(podcast, enclosure)
|
def getenclosure(podcast, item)
|
||||||
if ! enclosure.attribute("url").nil?
|
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
|
cast = enclosure.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])
|
replacement = @podcasts[podcast]["rename"][1].dup
|
||||||
|
if replacement.match(/%%DATE%%/)
|
||||||
|
replacement.sub!(/%%DATE%%/, date)
|
||||||
|
end
|
||||||
|
filename.sub!(@podcasts[podcast]["rename"][0], replacement)
|
||||||
end
|
end
|
||||||
@filelist[filename] = true
|
@filelist[filename] = true
|
||||||
if ! File.exists?("#{@podcasts[podcast]["savedir"]}/#{filename}")
|
if ! File.exists?("#{@podcasts[podcast]["savedir"]}/#{filename}")
|
||||||
|
|
@ -110,8 +131,8 @@ for podcast in @podcasts.keys.sort
|
||||||
@filelist = {}
|
@filelist = {}
|
||||||
|
|
||||||
xmldoc = REXML::Document.new(res.body)
|
xmldoc = REXML::Document.new(res.body)
|
||||||
xmldoc.elements.each("rss/channel/*/enclosure") {|enclosure|
|
xmldoc.elements.each("rss/channel/item") {|item|
|
||||||
files.push getenclosure(podcast, enclosure)
|
files.push getenclosure(podcast, item)
|
||||||
}
|
}
|
||||||
if @podcasts[podcast]["delete"]
|
if @podcasts[podcast]["delete"]
|
||||||
deleteold(podcast)
|
deleteold(podcast)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue