#!/usr/bin/env ruby

# == Synopsis
#
# Generate a podcast file from a directory of mp3 files. All subdirectories
# below indicated directory will be searched. 
#
# == Usage
# 
#   podcast --dir my/mp3/dir --out podcast.rss
#
# == Author
# Ed Summers <ehs@pobox.com>
#
# == Copyright
# Copyright (c) 2004 Ed Summers.
# Licensed under the same terms as Ruby.

require 'optparse'
require 'rdoc/usage'
require 'rubygems'
require_gem 'podcast'

# the location to look for mp3s
dir = ''

# the location to write the podcast file
podcast_file = nil 

# read options
opts = OptionParser.new
opts.on( "-d", "--dir VAL", String )        { |val| dir=val }
opts.on( "-o", "--out VAL", String )        { |val| podcast_file=val }
opts.parse(ARGV) rescue RDoc::usage( 'usage' )
RDoc::usage( 'usage' ) if dir == ''

# create podcast object
podcast = Podcast::Feed.new()

# add a directory
podcast.add_dir( dir )

# write off the rss
if podcast_file  
    file = File.new( podcast_file, 'w' )
    file.write( podcast.get_rss() )
    file.close
else 
    puts podcast.get_rss()
end
