You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
6.5 KiB
Ruby
187 lines
6.5 KiB
Ruby
#!/usr/bin/env ruby
|
|
$:.unshift('vendor/ruby-mediawiki/lib')
|
|
require 'mediawiki/dotfile'
|
|
require 'cgi'
|
|
require 'date'
|
|
require 'erb'
|
|
require 'net/http'
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Constants
|
|
|
|
RFC822 = "%a, %d %b %Y %T %z" # for Date::strftime
|
|
TPL_RSS = '<?xml version="1.0" encoding="utf-8"?>
|
|
<rss version="2.0"
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
|
|
xmlns:admin="http://webns.net/mvcb/"
|
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
|
|
|
<channel>
|
|
<title>radio chaotica podcast</title>
|
|
<link>http://entropia.de/wiki/Radio%20Chaotica</link>
|
|
<description>ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz</description>
|
|
<category>Talk Radio</category>
|
|
<generator>MediaWiki neinomat</generator>
|
|
<language>de</language>
|
|
<copyright>Entropia e.V. Karlsruhe</copyright>
|
|
|
|
<managingEditor>radio@entropia.de (Radio Chaotica)</managingEditor>
|
|
<pubDate><%=Time.now.strftime(RFC822) %></pubDate>
|
|
<image>
|
|
<url>http://podcast.entropia.de/chaotica-100x300-crappy.png</url>
|
|
<width>100</width>
|
|
<height>300</height>
|
|
<link>http://entropia.de/wiki/Radio%20Chaotica</link>
|
|
<title>Radio Chaotica</title>
|
|
</image>
|
|
|
|
<sy:updatePeriod>daily</sy:updatePeriod>
|
|
<sy:updateFrequency>1</sy:updateFrequency>
|
|
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
|
|
|
|
<itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz</itunes:subtitle>
|
|
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
|
|
ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz
|
|
</itunes:summary>
|
|
<itunes:image xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" href="http://podcast.entropia.de/chaotica-300x300-crappy.png"/>
|
|
|
|
<itunes:category xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" text="News & Politics"/>
|
|
<itunes:keywords xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">entropia,karlsruhe,ccc,hacking,computer,technology,society,chaosradio,chaos,politics</itunes:keywords>
|
|
<itunes:explicit xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">no</itunes:explicit>
|
|
|
|
<itunes:author xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">Entropia e.V. Karlsruhe</itunes:author>
|
|
<itunes:owner xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
|
|
<itunes:name>Entropia e.V. Karlsruhe</itunes:name>
|
|
<itunes:email>radio@entropia.de</itunes:email>
|
|
</itunes:owner>
|
|
|
|
<%= items %>
|
|
</channel></rss>
|
|
'
|
|
TPL_ITEM = '
|
|
<item>
|
|
<title><%= CGI::escapeHTML(episode["title"]) %></title>
|
|
<link><%= episode["url"] %></link>
|
|
<description><%= CGI::escapeHTML(episode["title"]) %></description>
|
|
<category>Talk Radio</category>
|
|
<enclosure url="<%= episode["enclosure_url"] %>" length="<%= episode["length"] %>" type="<%= episode["type"] %>" />
|
|
|
|
<guid isPermaLink="true"><%= episode["url"] %></guid>
|
|
<pubDate><%= episode["pubdate"] %></pubDate>
|
|
<comments><%= episode["discussion"] %></comments>
|
|
<content:encoded><%= CGI::escapeHTML(episode["title"]) %></content:encoded>
|
|
|
|
<author>radio@entropia.de</author>
|
|
|
|
<itunes:explicit xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">no</itunes:explicit>
|
|
<itunes:author xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">Entropia e.V. Karlsruhe</itunes:author>
|
|
<itunes:keywords xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">entropia,karlsruhe,ccc,hacking,computer,technology,society,chaosradio,chaos,politics</itunes:keywords>
|
|
<itunes:duration xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= episode["duration"] %></itunes:duration>
|
|
<itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(episode["title"]) %></itunes:subtitle>
|
|
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(episode["title"]) %></itunes:summary>
|
|
</item>
|
|
'
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Some helper functions
|
|
|
|
def parse_template(title, template)
|
|
template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}")
|
|
|
|
fields = {}
|
|
|
|
fields_string = @wiki.article(title).text.scan(template_re)[0][0]
|
|
|
|
inlink = 0
|
|
field = ""
|
|
fields_string += "|" unless fields_string.match(/\|$/)
|
|
fields_string.split(//).each do |c|
|
|
if c == "|" && inlink == 0
|
|
(key, value) = field.split(/=/)
|
|
fields[key] = value
|
|
field = ""
|
|
else
|
|
inlink += 1 if c == "["
|
|
inlink -= 1 if c == "]"
|
|
field += c
|
|
end
|
|
end
|
|
|
|
fields
|
|
end
|
|
|
|
def datum2isodate(datum)
|
|
return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1]
|
|
end
|
|
|
|
def head(url)
|
|
uri = URI.parse(url)
|
|
|
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
|
http.head(uri.path)
|
|
end
|
|
end
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Get episodes from wiki
|
|
|
|
@wiki = MediaWiki.dotfile(nil,'entropia')
|
|
|
|
template = "Vorlage:Radio Chaotica-Sendung"
|
|
episodes = []
|
|
@wiki.article(template).what_links_here.each do |page|
|
|
# puts page # DEBUG
|
|
if erste_sendung = parse_template(page, template)["erste_sendung"]
|
|
episode = {
|
|
"title" => page,
|
|
"url" => @wiki.article_url(page),
|
|
"discussion" => @wiki.article_url("Diskussion:#{page}"),
|
|
"enclosure_url" => parse_template(page, template)["download"],
|
|
"date" => Date.today(), # fallback
|
|
}
|
|
|
|
|
|
# Get a real date
|
|
erste_sendung.gsub!(/\s*um\s*\d+:\d+$/,"")
|
|
if erste_sendung !~ /^[0-9]{2}\.[0-9]{2}\.[0-9]{4}.*$/
|
|
$stderr.puts "Field '#{erste_sendung}' in #{episode["url"]} looks funny, fall back to today."
|
|
else
|
|
episode["date"] = Date.parse(datum2isodate(erste_sendung))
|
|
end
|
|
episode["pubdate"] = episode["date"].strftime(RFC822)
|
|
|
|
|
|
# Get content type and length
|
|
head = head(episode["enclosure_url"])
|
|
episode["length"] = head["content-length"]
|
|
episode["type"] = head["content-type"]
|
|
|
|
#FIXME
|
|
episode["duration"] = "00:59:59"
|
|
|
|
episodes.push(episode)
|
|
end
|
|
$stderr.puts "DEBUG: Only crawling one episode"; break
|
|
end
|
|
|
|
episodes = episodes.sort do |x,y|
|
|
y["date"] <=> x["date"]
|
|
end
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Generate RSS
|
|
|
|
items = ""
|
|
episodes.each do |episode|
|
|
items += ERB.new(TPL_ITEM).result(binding);
|
|
end
|
|
|
|
rss = ERB.new(TPL_RSS).result;
|
|
#puts rss #DEBUG
|
|
|
|
rssfile = File.new("/home/neingeist/public_html/chaotica.xml", "w")
|
|
rssfile.puts rss
|
|
rssfile.close
|