Created
May 21, 2015 07:10
-
-
Save salzig/5ccde03dd979f13528fb to your computer and use it in GitHub Desktop.
directory as itunes podcast experiment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#use Rack::Static, root: '' | |
feed = lambda { |env| | |
server = [env['SERVER_NAME'], env['SERVER_PORT']].compact.join(':') | |
# file = File.join(Dir.pwd,env['PATH_INFO']) | |
# if File.exist? file | |
# return [200, {'Content-Type'=>'video/quicktime', 'Content-Length'=>File.size(file).to_s}, [File.read(file)]] | |
# end | |
head = <<-HEAD | |
<?xml version="1.0" encoding="UTF-8"?> | |
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> | |
<channel> | |
<title>#{File.basename Dir.pwd}</title> | |
<description>#{File.basename Dir.pwd} - #{Dir['*.mov'].size} Episodes</description> | |
<link>http://#{server}</link> | |
<language>en-us</language> | |
<copyright>Copyright 2007</copyright> | |
<lastBuildDate>Mon, 18 May 2015 19:00:00 GMT</lastBuildDate> | |
<pubDate>Mon, 18 May 2015 19:00:00 GMT</pubDate> | |
<itunes:explicit>no</itunes:explicit> | |
<atom:link href="http://#{server}/feed.xml" rel="self" type="application/rss+xml" /> | |
<itunes:category text="Technology"/> | |
<itunes:owner> | |
<itunes:name>Ben</itunes:name> | |
<itunes:email>ben@rexin.at</itunes:email> | |
</itunes:owner> | |
HEAD | |
footer = "</channel></rss>" | |
entries = Dir['*.mov'].map do |file| | |
<<-ENTRY | |
<item> | |
<title>#{file.split('.').first.split('-')[1..99].join(' ')}</title> | |
<link>http://#{server}/#{file}</link> | |
<enclosure url="http://#{server}/#{file}" type="video/quicktime" length="#{File.size file}" /> | |
<description>Verbose description of the episode.</description> | |
<guid>http://#{server}/#{file}</guid> | |
<pubDate>Mon, 18 May 2015 19:00:00 GMT</pubDate> | |
</item> | |
ENTRY | |
end.join($/) | |
response = [head, entries, footer].join $/ | |
[200, {'Content-Type'=>'application/rss+xml'}, [response]] | |
} | |
run Rack::URLMap.new( { | |
"/" => Rack::Directory.new( "" ), | |
"/feed.xml" => feed | |
} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment