-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfolder2podcast.rb
52 lines (44 loc) · 1.26 KB
/
folder2podcast.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'sinatra'
hostname = `ifconfig`.split("\n").grep(/broadcast/).first.gsub(/.*inet (\d+\.\d+\.\d+\.\d+).*/, '\1') + ":4567"
get '/' do
feed = "http://#{hostname}/feed?d=/Users/richard/Downloads/"
"Visit <a href='#{feed}'>#{feed}</a> in your podcatcher!"
end
get '/feed' do
if params[:d].nil?
return "Please specify <code>d=/path/to/audiofiles</code>"
end
path = params[:d]
items = Dir.glob(path + "*.mp3").map do |f|
name = f.gsub(path, '')
{
'title' => name,
'description' => name,
'pub_date' => File.mtime(f),
'url' => "http://#{hostname}/item?f=#{URI.encode(f)}"
}
end
builder do |xml|
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title "#{path} Podcast"
xml.description "A feed of all the mp3 files in the #{path} folder"
xml.link "http://#{hostname}/feed"
items.each do |item|
xml.item do
xml.title item['title']
xml.description item['description']
xml.pubDate item['pub_date'].rfc822
xml.link item['url']
xml.guid item['url']
xml.enclosure item['url']
end
end
end
end
end
end
get '/item' do
send_file params[:f]
end