Subscribing to podcasts from a local directory

30 Jun 2006 21:59 - (1) comments

At this moment I'm subscribed to the IT Conversations, Rails and Argos podcasts. Occasionally I download a single podcast that seems interesting. But I never seem to listen to these single podcasts. Finding them in my library seems to much of a hassle.

So I created a little Ruby script that creates a podcast rss feed from a given directory.
Too bad iTunes doesn't recognize file://... as a podcast url. Specifying the server makes the script less clean.

You can call this script from your crontab rss_podcast_dirs.rb /directory/with/podcasts http://localhost/your/podcast/podcasts.rss.

#!/usr/bin/ruby -w
#
# Creates a rss feed of podcasts in specified location on server
#

require 'find'
require 'rss/maker'
require 'uri'
require 'htmlentities'

fail "\nUsage: " + File.basename($0) + " feed_dir podcast_url .......\n" unless ARGV.size > 1

feed_dir, podcast_url = $*[0], $*[1]
feed_file = File.basename(podcast_url)
server_dir = File.dirname(podcast_url) + "/"

def escape_xml text
text.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;').gsub("'", '&apos;').gsub('"', '&quot;')
end

def find_files(dir)
files = Array.new
Find.find(dir) { |file| files << file unless (File.basename(file)[0, 1] == ".") }
files
end

rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = "Podcasts from #{feed_dir}".encode_entities
maker.channel.link = podcast_url
maker.channel.description = maker.channel.title
find_files(feed_dir).sort { | y, x |
File.mtime(x) <=> File.mtime(y)
}.collect { |file|
item = maker.items.new_item
item.title = File.basename(file).encode_entities
item.date = File.mtime(file)
item.link =
item.guid.content =
item.enclosure.url =
URI.escape((file).gsub(feed_dir, server_dir))
item.enclosure.length = File.stat(file).size
item.enclosure.type = "audio/mpeg"
}
end

podCastFile = File.new(feed_dir + feed_file , "w")
podCastFile.puts rss
podCastFile.close

Comments

You could use the same script to view custom vodcasts. The only thing you'd need to write is a script that downloads Real Player tv shows and converts them to .mov or .avi.

On 01 Jul 11:03 by Echo

Comments have been closed.

Admin