Skip to content

Instantly share code, notes, and snippets.

@guillermo
Created December 20, 2008 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillermo/38330 to your computer and use it in GitHub Desktop.
Save guillermo/38330 to your computer and use it in GitHub Desktop.
klubbersfm.comunidadspaceofsound.net/
#!/usr/local/bin/ruby
# This is the software to extract klubbers fm radio podcast.
#
# You can access the klubbers fm podcast in:
# http://klubbersfm.comunidadspaceofsound.net/
#
require 'rubygems'
require 'sinatra'
require 'hpricot'
require 'open-uri'
require 'rack/cache'
use Rack::Cache,
:verbose => true,
:metastore => "file:/tmp/klubbersfm/cache/meta",
:entitystore => "file:/tmp/klubbersfm/cache/body"
File.open('/tmp/klubbersfm.pid','w'){|f| f.write $$}
Sinatra::Application.default_options.merge!(
:port => 7777,
:address => '127.0.0.1'
)
get '/' do
haml :index
end
get '/index.rss' do
response["Cache-Control"] = "max-age=86400, public"
builder :podcast
end
use_in_file_templates!
#end
__END__
@@ index
!!!
%html
%script{:src => 'itunes.js'}
<title>Podcast no oficial de klubbersfm</title>
:plain
<link rel="stylesheet" href="http://www.blueprintcss.org/blueprint/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="http://www.blueprintcss.org/blueprint/print.css" type="text/css" media="print">
<!--[if lt IE 8]><link rel="stylesheet" href="http://www.blueprintcss.org/blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
%body
.container
.span-24
%h1 Podcast de Klubbers FM
%p Este es el podcast no oficial de klubbers FM
.span-6
%h2 Usar este podcast
%p Para usar este podcast inserta el siguiente enlace a tu programa de podcasts preferido
%ul
%li
%a{:href => 'http://feeds.feedburner.com/klubbers'} "http://feeds.feedburner.com/klubbers"
.span-6
%h2 Motivaciones
%p Debido a que el player de la web nunca me ha funcionado y que no tiene podcast oficial, realice este sencillo podcast que busca en la web de klubbers por novedades.
%p El programa son apenas unas 70 lineas, con licencia BSD, y se puede descargar desde http://gist.github.com/38330
.span-6
%h2 Itunes
%p Subscribete a este podcast en <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=328171626"><img src="http://ax.phobos.apple.com.edgesuite.net/images/badgeitunes61x15dark.gif" alt="iTunes" /></a>
.span-6.last
%h2 Author
%p Guillermo Alvarez < guillermo @ cientifico.net >
@@ podcast
doc = Hpricot(open('http://www.klubbers.com/player.php'))
last_pub = Time.local(2000)
reg = /player\.php\?dia\=(\d*)\&mes\=(\d*)\&anio\=(\d*)/
episodes = (doc/"option").map do |e|
begin
# Get title
title = e.inner_html.split("@").first
# Get date
value = e.attributes["value"]
day, month, year = value.match(reg).to_a[1..-1].map{|d| d.to_i}
# Get mp3 url
date = "%.2d_%.2d_%.2d" % [day,month,year]
url ="http://www.klubbers.com/radio/radio_#{date}/wimpy.php?action=getstartupdirlist"
puts "Getting #{url}"
body = open(url).read
mp3 = body.match(/=([^|]*)/).to_a[1]
# Generate pubDate
pubdate = Time.local(year,month,day)
last_pub = pubdate if pubdate > last_pub
[ mp3, title, pubdate.rfc822]
rescue => e
require 'ruby-debug'
debugger
puts 'touche'
end
end
xml.instruct!
xml.rss :version => '2' do |rss|
rss.channel do |chan|
chan.title "Klubbers FM Radio"
chan.description "Klubbers FM Radio Podcast\nPodcast no oficial del programa de radio Klubbers FM, emitido por Loca FM (España)"
chan.link "http://klubbersfm.comunidadspaceofsound.net"
chan.languge "es-es"
chan.lastBuildDate Time.now.to_s
chan.pubDate last_pub.rfc822
episodes.each do |episode|
chan.item do |i|
i.title episode[1]
i.link episode[0]
i.description episode[1]
i.enclosure :url => episode[0] , :type => 'audio/mpeg'
i.category "Podcasts"
i.pubDate episode[2]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment